-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathlongcook.cc
60 lines (56 loc) · 1.25 KB
/
longcook.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// https://www.codechef.com/FEB20A/problems/LONGCOOK
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int n = 400 * 12;
int s[n];
bool isleap(int y) {
if (y % 400 == 0) return 1;
if (y % 100 == 0) return 0;
return y % 4 == 0;
}
int main() {
cin.tie(0), ios::sync_with_stdio(0);
ll d = 0;
for (int i = 0; i < n; i++) {
int y = (i / 12) + 1, m = (i % 12) + 1;
if (m == 2) {
if (isleap(y)) {
if (d % 7 == 5) s[i]++;
d += 29;
} else {
if (d % 7 >= 5) s[i]++;
d += 28;
}
} else if (m == 4 || m == 6 || m == 9 || m == 11) d += 30;
else d += 31;
if (i) s[i] += s[i-1];
}
int t;
cin >> t;
while (t--) {
ll m1, y1, m2, y2;
cin >> m1 >> y1 >> m2 >> y2;
m1--, y1--, m2--, y2--;
ll i1 = y1 * 12 + m1;
ll i2 = y2 * 12 + m2;
ll l = i1 ? ((i1 - 1) / n + 1) : 0;
ll r = (i2 + 1) / n - 1;
if (l > r) {
ll c = (i2 - i1) / n * s[n-1];
i1 %= n;
i2 %= n;
if (i1 > i2) c += s[n-1];
c += s[i2];
if (i1) c -= s[i1-1];
cout << c << '\n';
continue;
}
i1 %= n;
i2 %= n;
ll c = s[n-1] * (r - l + 1);
if (i1) c += s[n-1] - s[i1-1];
if (i2 < n-1) c += s[i2];
cout << c << '\n';
}
}