#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, nrec;
int lx[N], ly[N], rx[N], ry[N];
long long ans = 1e18;
int get(int t, int l, int r) {
// count the number of x such that l <= x <= r and (x / k) % 2 == t
if (l / k == r / k) {
if ((l / k) % 2 == t) return r - l + 1; else return 0;
}
int ret = 0;
if ((l / k) % 2 == t) ret += ((l / k) + 1) * k - l;
if ((r / k) % 2 == t) ret += r - (r / k) * k + 1;
l = (l / k) + 1;
r = (r / k) - 1;
if (l % 2 != t) ++l;
if (r % 2 != t) --r;
ret += max(0, (r - l) / 2 + 1) * k;
return ret;
}
void solve() {
for (int t = 0; t < 2; ++t) {
int row[2] = {0, 0}, col[2] = {0, 0};
for (int i = 0; i < 2; ++i) {
row[i] = get(i, 0, n - 1);
col[i] = get(i, 0, n - 1);
}
// black cells: (x, y) such that (x + y) == t (modulo 2)
long long cur = 0;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) if ((i + j) % 2 == t) {
cur += 1LL * row[i] * col[j];
}
}
for (int rec = 1; rec <= nrec; ++rec) {
for (int i = 0; i < 2; ++i) {
row[i] = get(i, lx[rec], rx[rec]);
col[i] = get(i, ly[rec], ry[rec]);
}
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
if ((i + j) % 2 == t) cur -= 1LL * row[i] * col[j];
else cur += 1LL * row[i] * col[j];
}
}
}
ans = min(ans, cur);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> nrec;
for (int i = 1; i <= nrec; ++i) {
cin >> lx[i] >> ly[i] >> rx[i] >> ry[i];
--lx[i]; --ly[i]; --rx[i]; --ry[i];
}
for (k = 1; k < n; ++k) if (n % k == 0) {
solve();
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
1444 KB |
Output is correct |
2 |
Correct |
10 ms |
1444 KB |
Output is correct |
3 |
Correct |
25 ms |
1444 KB |
Output is correct |
4 |
Correct |
25 ms |
1444 KB |
Output is correct |
5 |
Correct |
33 ms |
1444 KB |
Output is correct |
6 |
Correct |
20 ms |
1444 KB |
Output is correct |
7 |
Correct |
7 ms |
1444 KB |
Output is correct |
8 |
Correct |
19 ms |
1444 KB |
Output is correct |
9 |
Correct |
49 ms |
1932 KB |
Output is correct |
10 |
Correct |
30 ms |
1932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1932 KB |
Output is correct |
2 |
Correct |
2 ms |
1932 KB |
Output is correct |
3 |
Correct |
2 ms |
1932 KB |
Output is correct |
4 |
Correct |
3 ms |
1932 KB |
Output is correct |
5 |
Correct |
2 ms |
1932 KB |
Output is correct |
6 |
Correct |
2 ms |
1932 KB |
Output is correct |
7 |
Correct |
2 ms |
1932 KB |
Output is correct |
8 |
Correct |
2 ms |
1932 KB |
Output is correct |
9 |
Correct |
2 ms |
1932 KB |
Output is correct |
10 |
Correct |
2 ms |
1932 KB |
Output is correct |
11 |
Correct |
2 ms |
1932 KB |
Output is correct |
12 |
Correct |
2 ms |
1932 KB |
Output is correct |
13 |
Correct |
2 ms |
1932 KB |
Output is correct |
14 |
Correct |
4 ms |
1932 KB |
Output is correct |
15 |
Correct |
2 ms |
1932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1932 KB |
Output is correct |
2 |
Correct |
2 ms |
1932 KB |
Output is correct |
3 |
Correct |
2 ms |
1932 KB |
Output is correct |
4 |
Correct |
3 ms |
1932 KB |
Output is correct |
5 |
Correct |
2 ms |
1932 KB |
Output is correct |
6 |
Correct |
2 ms |
1932 KB |
Output is correct |
7 |
Correct |
2 ms |
1932 KB |
Output is correct |
8 |
Correct |
2 ms |
1932 KB |
Output is correct |
9 |
Correct |
2 ms |
1932 KB |
Output is correct |
10 |
Correct |
2 ms |
1932 KB |
Output is correct |
11 |
Correct |
2 ms |
1932 KB |
Output is correct |
12 |
Correct |
2 ms |
1932 KB |
Output is correct |
13 |
Correct |
2 ms |
1932 KB |
Output is correct |
14 |
Correct |
4 ms |
1932 KB |
Output is correct |
15 |
Correct |
2 ms |
1932 KB |
Output is correct |
16 |
Correct |
24 ms |
1932 KB |
Output is correct |
17 |
Correct |
40 ms |
1932 KB |
Output is correct |
18 |
Correct |
98 ms |
2156 KB |
Output is correct |
19 |
Correct |
346 ms |
2156 KB |
Output is correct |
20 |
Correct |
443 ms |
2156 KB |
Output is correct |
21 |
Correct |
42 ms |
2156 KB |
Output is correct |
22 |
Correct |
3 ms |
2156 KB |
Output is correct |
23 |
Correct |
55 ms |
2156 KB |
Output is correct |
24 |
Correct |
65 ms |
2156 KB |
Output is correct |
25 |
Correct |
12 ms |
2156 KB |
Output is correct |
26 |
Correct |
41 ms |
2156 KB |
Output is correct |
27 |
Correct |
70 ms |
2156 KB |
Output is correct |
28 |
Correct |
69 ms |
2156 KB |
Output is correct |
29 |
Correct |
16 ms |
2156 KB |
Output is correct |
30 |
Correct |
4 ms |
2156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
1444 KB |
Output is correct |
2 |
Correct |
10 ms |
1444 KB |
Output is correct |
3 |
Correct |
25 ms |
1444 KB |
Output is correct |
4 |
Correct |
25 ms |
1444 KB |
Output is correct |
5 |
Correct |
33 ms |
1444 KB |
Output is correct |
6 |
Correct |
20 ms |
1444 KB |
Output is correct |
7 |
Correct |
7 ms |
1444 KB |
Output is correct |
8 |
Correct |
19 ms |
1444 KB |
Output is correct |
9 |
Correct |
49 ms |
1932 KB |
Output is correct |
10 |
Correct |
30 ms |
1932 KB |
Output is correct |
11 |
Correct |
2 ms |
1932 KB |
Output is correct |
12 |
Correct |
2 ms |
1932 KB |
Output is correct |
13 |
Correct |
2 ms |
1932 KB |
Output is correct |
14 |
Correct |
3 ms |
1932 KB |
Output is correct |
15 |
Correct |
2 ms |
1932 KB |
Output is correct |
16 |
Correct |
2 ms |
1932 KB |
Output is correct |
17 |
Correct |
2 ms |
1932 KB |
Output is correct |
18 |
Correct |
2 ms |
1932 KB |
Output is correct |
19 |
Correct |
2 ms |
1932 KB |
Output is correct |
20 |
Correct |
2 ms |
1932 KB |
Output is correct |
21 |
Correct |
2 ms |
1932 KB |
Output is correct |
22 |
Correct |
2 ms |
1932 KB |
Output is correct |
23 |
Correct |
2 ms |
1932 KB |
Output is correct |
24 |
Correct |
4 ms |
1932 KB |
Output is correct |
25 |
Correct |
2 ms |
1932 KB |
Output is correct |
26 |
Correct |
24 ms |
1932 KB |
Output is correct |
27 |
Correct |
40 ms |
1932 KB |
Output is correct |
28 |
Correct |
98 ms |
2156 KB |
Output is correct |
29 |
Correct |
346 ms |
2156 KB |
Output is correct |
30 |
Correct |
443 ms |
2156 KB |
Output is correct |
31 |
Correct |
42 ms |
2156 KB |
Output is correct |
32 |
Correct |
3 ms |
2156 KB |
Output is correct |
33 |
Correct |
55 ms |
2156 KB |
Output is correct |
34 |
Correct |
65 ms |
2156 KB |
Output is correct |
35 |
Correct |
12 ms |
2156 KB |
Output is correct |
36 |
Correct |
41 ms |
2156 KB |
Output is correct |
37 |
Correct |
70 ms |
2156 KB |
Output is correct |
38 |
Correct |
69 ms |
2156 KB |
Output is correct |
39 |
Correct |
16 ms |
2156 KB |
Output is correct |
40 |
Correct |
4 ms |
2156 KB |
Output is correct |
41 |
Correct |
305 ms |
2156 KB |
Output is correct |
42 |
Correct |
72 ms |
2156 KB |
Output is correct |
43 |
Correct |
152 ms |
2156 KB |
Output is correct |
44 |
Correct |
80 ms |
2156 KB |
Output is correct |
45 |
Correct |
52 ms |
2156 KB |
Output is correct |
46 |
Correct |
328 ms |
2156 KB |
Output is correct |
47 |
Correct |
52 ms |
2156 KB |
Output is correct |
48 |
Correct |
123 ms |
2156 KB |
Output is correct |
49 |
Correct |
68 ms |
2156 KB |
Output is correct |
50 |
Correct |
1597 ms |
2156 KB |
Output is correct |
51 |
Correct |
1633 ms |
2228 KB |
Output is correct |
52 |
Correct |
1528 ms |
2228 KB |
Output is correct |
53 |
Correct |
1639 ms |
2228 KB |
Output is correct |
54 |
Correct |
1527 ms |
2228 KB |
Output is correct |
55 |
Correct |
1745 ms |
2284 KB |
Output is correct |
56 |
Correct |
1458 ms |
2284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
34 ms |
1444 KB |
Output is correct |
10 |
Correct |
10 ms |
1444 KB |
Output is correct |
11 |
Correct |
25 ms |
1444 KB |
Output is correct |
12 |
Correct |
25 ms |
1444 KB |
Output is correct |
13 |
Correct |
33 ms |
1444 KB |
Output is correct |
14 |
Correct |
20 ms |
1444 KB |
Output is correct |
15 |
Correct |
7 ms |
1444 KB |
Output is correct |
16 |
Correct |
19 ms |
1444 KB |
Output is correct |
17 |
Correct |
49 ms |
1932 KB |
Output is correct |
18 |
Correct |
30 ms |
1932 KB |
Output is correct |
19 |
Correct |
2 ms |
1932 KB |
Output is correct |
20 |
Correct |
2 ms |
1932 KB |
Output is correct |
21 |
Correct |
2 ms |
1932 KB |
Output is correct |
22 |
Correct |
3 ms |
1932 KB |
Output is correct |
23 |
Correct |
2 ms |
1932 KB |
Output is correct |
24 |
Correct |
2 ms |
1932 KB |
Output is correct |
25 |
Correct |
2 ms |
1932 KB |
Output is correct |
26 |
Correct |
2 ms |
1932 KB |
Output is correct |
27 |
Correct |
2 ms |
1932 KB |
Output is correct |
28 |
Correct |
2 ms |
1932 KB |
Output is correct |
29 |
Correct |
2 ms |
1932 KB |
Output is correct |
30 |
Correct |
2 ms |
1932 KB |
Output is correct |
31 |
Correct |
2 ms |
1932 KB |
Output is correct |
32 |
Correct |
4 ms |
1932 KB |
Output is correct |
33 |
Correct |
2 ms |
1932 KB |
Output is correct |
34 |
Correct |
24 ms |
1932 KB |
Output is correct |
35 |
Correct |
40 ms |
1932 KB |
Output is correct |
36 |
Correct |
98 ms |
2156 KB |
Output is correct |
37 |
Correct |
346 ms |
2156 KB |
Output is correct |
38 |
Correct |
443 ms |
2156 KB |
Output is correct |
39 |
Correct |
42 ms |
2156 KB |
Output is correct |
40 |
Correct |
3 ms |
2156 KB |
Output is correct |
41 |
Correct |
55 ms |
2156 KB |
Output is correct |
42 |
Correct |
65 ms |
2156 KB |
Output is correct |
43 |
Correct |
12 ms |
2156 KB |
Output is correct |
44 |
Correct |
41 ms |
2156 KB |
Output is correct |
45 |
Correct |
70 ms |
2156 KB |
Output is correct |
46 |
Correct |
69 ms |
2156 KB |
Output is correct |
47 |
Correct |
16 ms |
2156 KB |
Output is correct |
48 |
Correct |
4 ms |
2156 KB |
Output is correct |
49 |
Correct |
305 ms |
2156 KB |
Output is correct |
50 |
Correct |
72 ms |
2156 KB |
Output is correct |
51 |
Correct |
152 ms |
2156 KB |
Output is correct |
52 |
Correct |
80 ms |
2156 KB |
Output is correct |
53 |
Correct |
52 ms |
2156 KB |
Output is correct |
54 |
Correct |
328 ms |
2156 KB |
Output is correct |
55 |
Correct |
52 ms |
2156 KB |
Output is correct |
56 |
Correct |
123 ms |
2156 KB |
Output is correct |
57 |
Correct |
68 ms |
2156 KB |
Output is correct |
58 |
Correct |
1597 ms |
2156 KB |
Output is correct |
59 |
Correct |
1633 ms |
2228 KB |
Output is correct |
60 |
Correct |
1528 ms |
2228 KB |
Output is correct |
61 |
Correct |
1639 ms |
2228 KB |
Output is correct |
62 |
Correct |
1527 ms |
2228 KB |
Output is correct |
63 |
Correct |
1745 ms |
2284 KB |
Output is correct |
64 |
Correct |
1458 ms |
2284 KB |
Output is correct |
65 |
Correct |
1 ms |
2284 KB |
Output is correct |
66 |
Correct |
1 ms |
2284 KB |
Output is correct |
67 |
Correct |
1728 ms |
2284 KB |
Output is correct |
68 |
Correct |
1730 ms |
2284 KB |
Output is correct |
69 |
Correct |
1590 ms |
2284 KB |
Output is correct |
70 |
Correct |
1587 ms |
2284 KB |
Output is correct |
71 |
Correct |
1647 ms |
2284 KB |
Output is correct |
72 |
Correct |
1586 ms |
2284 KB |
Output is correct |
73 |
Correct |
1602 ms |
2284 KB |
Output is correct |
74 |
Correct |
1749 ms |
2284 KB |
Output is correct |
75 |
Correct |
1626 ms |
2284 KB |
Output is correct |
76 |
Correct |
1766 ms |
2284 KB |
Output is correct |
77 |
Correct |
270 ms |
2288 KB |
Output is correct |
78 |
Correct |
81 ms |
2288 KB |
Output is correct |
79 |
Correct |
180 ms |
2288 KB |
Output is correct |
80 |
Correct |
196 ms |
2288 KB |
Output is correct |
81 |
Correct |
173 ms |
2288 KB |
Output is correct |
82 |
Correct |
139 ms |
2288 KB |
Output is correct |
83 |
Correct |
107 ms |
2288 KB |
Output is correct |
84 |
Correct |
1062 ms |
2288 KB |
Output is correct |
85 |
Correct |
1863 ms |
2288 KB |
Output is correct |
86 |
Correct |
4 ms |
2288 KB |
Output is correct |
87 |
Correct |
2 ms |
2288 KB |
Output is correct |
88 |
Correct |
1851 ms |
2288 KB |
Output is correct |
89 |
Correct |
365 ms |
2288 KB |
Output is correct |
90 |
Correct |
2 ms |
2288 KB |
Output is correct |