LONGCOOK-Editorial-solution

sorry i forgot to upload the explanation :
in this problem the in every 400 years no. of days on which cookoff and long challenge strikes are 101. so, we divide the diff b/w the years with 400 and multiply it with 101 . and then shift the year y1 by y1 + ((y2-y1)/400)*400 which will shift year y1 near to y2 and diff b/w these years is now less than 400 now. it will not give you “TLE” and after that you just have to find the days on which cookoff and long intersect b/w y1 and y2.
for that you see that video how to find day from any date - YouTube
and apply some trick to just find it in feb= month and date = 1 and if you cant understand why feb as month and date =1 only then ask it to me.

#include <bits/stdc++.h> 
using namespace std; 

int dayofweek(int d, int m, long int y) 
{ 
	static int t[] = { 0, 3, 2, 5, 0, 3, 
					5, 1, 4, 6, 2, 4 }; 
	y -= m < 3; 
	return ( y + y / 4 - y / 100 + 
			y / 400 + t[m - 1] + d) % 7; 
} 

int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
long int m1,m2,y1,y2;
cin>>m1>>y1>>m2>>y2;
if(m1>2)
{y1 = y1+1;}
if(m2<2)
{y2 = y2-1;}
long int dif=0;


dif = ((y2 - y1)/400)*101;
y1  = y1+(((y2-y1)/400)*400);
for(long int j=y1;j<=y2;j++)
{
	int c=0;
int day = dayofweek(1, 2, j);
if(((j% 4 == 0) && (j% 100 != 0)) || (j% 400 == 0))
{c=1;}
	if(day == 6)
	{dif++;}
	else if(day==0 && c!=1) 
	{dif++;} 
}

cout<<dif<<endl;


}
return 0;
}

Could you please elaborate? I really cannot understand.

1 Like

It is not an editorial, please write the correct topic from the next time.

2 Likes

sorry bro, i can tell you the concept behind that.
in this problem the in every 400 years no. of days on which cookoff and long challenge strikes are 101. so, we divide the diff b/w the years with 400 and multiply it with 101 . and then shift the year y1 by y1 + ((y2-y1)/400)*400 which will shift year y1 near to y2 and diff b/w these years is now less than 400 now. it will not give you “TLE” and after that you just have to find the days on which cookoff and long intersect b/w y1 and y2.
for that you see that video how to find day from any date - YouTube
and apply some trick to just find it in feb= month and date = 1 and if you cant understand why feb as month and date =1 only then ask it to me.
and another sorry for inconvinence.

1 Like

in this problem the in every 400 years no. of days on which cookoff and long challenge strikes are 101. so, we divide the diff b/w the years with 400 and multiply it with 101 . and then shift the year y1 by y1 + ((y2-y1)/400)*400 which will shift year y1 near to y2 and diff b/w these years is now less than 400 now. it will not give you “TLE” and after that you just have to find the days on which cookoff and long intersect b/w y1 and y2.
for that you see that video how to find day from any date - YouTube
and apply some trick to just find it in feb= month and date = 1 and if you cant understand why feb as month and date =1 only then ask it to me.

It’s okay, I haven’t seen the problem. But just telling you that you need to explain each and every part in an editorial.

1 Like

thnks but i prefer you to solve this problem because i found three different way to solve this.

Yes, I’ll try. Thanks for your opinion :slight_smile:

1 Like

Can you please tell why feb ? and why date =1? I have been struggling to find about it for long

because feb is the only moth when they both contest strike and why day = 1 see this video
https://www.youtube.com/watch?v=45vy5OBw4k4&t=168s

Yes I got it .
Thanks for replying :slightly_smiling_face:

1 Like

sorry i am busy on codeforces now a days . thats why i havn’t see codechef discuss for long time.