LONGCOOK - Editorial

I used the same logic but getting wrong ans

I solved this problem with similar approach.
I got partial point for it , you can see my solution. link is already above-mentioned.
For the proof of this logic.
You can see the table.
Link is https://drive.google.com/file/d/1RNLDUIsocFInSuPXJk-8q_7GRdxR2AFH/view?usp=sharing

1 Like

Years like 1900 2100 2200 are not leap years, so the 28-year cycle is broken at each of these years. This makes the coding more tricky, as you need to divide the range into separate centuries.

4 Likes

I didn’t realize that this was true, but it’s not necessary to solve the problem with this observation.

2 Likes

My Approach.

Hint: Level 1 Observe that each month long challenge starts on First Friday so First Friday must have to come on either of the dates 1 2 3 4 5 6 7 so lets pick first 5 days then max time till long challenge will run is on 15 th of february and remaining days if considered not a leap year are 13 and obviously there will be two sundays in those thirteen days and

also one point of obervation is that if a month is of more than 29 days then there will be no overlap thus we are safe for every month except february now what if friday comes on 6th of february so challenge wiill last upto 16th and so there will be 12 days left if normal year and 13 days if its leap year so when it is a leap year no issue is there when friday is on 6th so issue comes when Friday is there on 6th and year is non leap year also another case of issue is that when friday comes in any of the years february on 6th of february so our main task reduces to finding those yrs in which friday comes on 7th of feb and those non leap years on which friday comes on 6th of feb.

now what was my trick to reduce the overall complexity of the solution from O(y2-y1) to O (400) per query was that at first I found a general pattern of these years that in which years these overlapping situations is coming and also my soul point of observation is that in every 400 years these situations comes 101 times and also repeatedly modulo 4 you can observe yourself by running brute force and getting when there is overlap you can brute force upto 2000 years and observe these array of 101 years what I found was like this I am printing it here for you. {3 , 9 ,14 , 15 ,20 , 25 , 26 ,31 , 37 ,42 , 43 ,48 , 53 , 54 ,59 , 65 ,70 , 71 ,76 , 81 , 82 ,87 , 93 ,98 , 99 ,105 ,110 , 111 ,116 , 121 , 122 ,127 , 133 ,138 , 139 ,144 , 149 , 150 ,155 , 161 ,166 , 167 ,172 , 177 , 178 ,183 , 189 ,194 , 195 ,200 , 201 ,206 , 207 ,212 , 217 , 218 ,223 , 229 ,234 , 235 ,240 , 245 , 246 ,251 , 257 ,262 , 263 ,268 , 273 , 274 ,279 , 285 ,290 , 291 ,296 , 302 , 303 ,308 , 313 , 314 ,319 , 325 ,330 , 331 ,336 , 341 , 342 ,347 , 353 ,358 , 359 ,364 , 369 , 370 ,375 , 381 ,386 , 387 ,392 , 397 , 398}

observe 2003 2009 2014 2015 2020 and 2025 all values are repeated every 400 years and thus our task becomes very simple that if the difference in y2 and y1 is lesser than 400 then we can just simply traverse and enumerate ourselves and if also the differnece is larger we know that we have 101 years per every 400 perfect such years in that way I optimised my approach for all cases and it runs max O(400) per test case thus overall time complexity reduces to 0.4 seconds and thus it is solvable.

1 Like

if i am not wrong you come up this observation by assuming every 4th year is a leap year. right? and it is wrong because 96th year is leap year but 100 is not. so here we can’t say Jan 1 will be Monday for every 28 years of cycle.

1 Like

I think that is obvious by a little skimming of calendar

if it is not leap year it can only happen in feb given that first day of feb is either sat or sun.
if it is leap it can only happen in feb given that first day is sat.
not other month can have intersection of contests.

Yes, I agree to your point. I assumed every 4th year as a leap year.

1 Like

give me test cases in which my submission is failed.
my submission

Well, I was too lazy to do even a little skimming.

1 Like

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

1 Like

Try

Test case

1
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

2 Likes

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