LONGCOOK - Editorial

Still, you’re great at your skills…I admire you :innocent:

1 Like


Test case

1 201 2 201

I used the same approach as mentioned by you, but i got TLE.
@anon31329220 can you please tell me why i got TLE.
Here is my solution (CodeChef: Practical coding for everyone)

I have been trying this for days now, and still can’t figure out why my code is WA and TLE. I have used loop for only 400 years. Here is my code :- CodeChef: Practical coding for everyone

there’s a pattern for the overlapping feb years every 1,5,6,5,1,5,5, 1,5,6,5,1,5,5, 1,5,6,5,1,5,5, …

if it works , don’t touch it :slight_smile:

can anyone here to help me to understand this plzzzz !!!1

If you don’t understand the quick explanation then read the full explanation


Java libraries could be slow, try to not use the libraries.


Test case

12 205
1 207

I was attempting ’ Long Contest and Cook Off Overlaps
Approach: Using JAVA Calendar class.
Issue: Getting TLE Verdict.


I know JAVA Libs can be slow in this case, but still if anyone knows a way to get through this…

Kindly tell me whether I can approach this using Calendar class or not, if yes then how to optimize my code so to get AC.

Thanks in advance.

I suspect that the Java Calendar class was not made for such big inputs.

Can you please make more clear to me what is meant by:

we will use the standard trick of splitting the range [l,r][l, r][l,r] into 2 prefixes: prefix r minus prefix l-1. This will make calculations simpler later on.

and also,

To pass the second subtask with…, … calculate the prefix sums. The prefix sums will allow us to answer queries in constant time.

I might be asking something too simple, but I am new to competitive programming and following editorials word by word, so ur answer matters in my learning curve.


1 Like

Both questions should be clear if you study prefix sums enough.

My Soln:

someone plese help me with this !! all test case are working correct but still wrong answer is coming

Using this fact, you can solve without regarding each month; the months are only necessary when checking whether the starting year and the ending year contains February. If the starting month is March or later, simply increase the starting year by one. Similarly, if the ending month is January, decrease the ending year by one. Then the answer is the number of years between them with their February satisfying one of the above conditons.


This question was observation based , by some googling you can easily get Find day of the week for a given date - GeeksforGeeks , for every 400 years, if a year is leap, our condition is true on (feb if day is ->saturday) . If year is not a leap year, our condition gets true on (feb if day is either Saturday or Sunday). So , I have taken a hash map to store all the values from 1st year to 400th year.I tried running it and found out in 400 years , we get 101 years that satisfies our condition. As, the pattern gets repeated , so I have used simple division and modulo(remainder) operation to solve this. You just need to count the years buddy, in question you are given two dates(starting and ending date). I have taken ans=end_yr_count-start_yr_count. If the starting year also satisfies the condition then you need to add +1 to it i.e. ans=end_yr_count-start_yr_count+1.