nus-cs2030 / 2021-s2

2 stars 2 forks source link

Project Level 5 Test Case 5_4 #251

Open rendao1010 opened 3 years ago

rendao1010 commented 3 years ago

Summary

Hi, when submitting my project to CodeCrunch, my code runs into the issue of time limit exceeded. However, all the lines of output before it exceeds the time limit seems to work fine. Has anyone run into the same issue, or have any suggestions how I can go about solving this? Thank you!

Screenshots (if any):

image

yuyitan commented 3 years ago

Are you pre-generating your Customer serviceTimes into any data structure like ArrayList? If so, you can try use a Supplier instead.

rendao1010 commented 3 years ago

image

This is my code in my Main5.java to generate the Customers! I only call the Supplier's get method in the Serve class, when deciding what time the Done event should be scheduled.

chengseong commented 3 years ago

It could be due to your other methods in your classes. Are there any methods using nested for loops?

rendao1010 commented 3 years ago

I have one method in my Wait class that uses a nested for loop, but it only checks through the server's waiting list to add up all the customer service times.

image

In addition, after cutting down significantly on the number of for loops within my code, I am still only able to reach line 2552 of test case 5_4.