#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long INF = 1e18 + 5;
const int MAXN = 1e6;
const int base = 317;
typedef long long ll;
const ll bs = 1e5 + 1;
const ll mod = 998244353;
#define int ll
ll ans = INF, n, k, xx[N], yy[N], xx1[N], yy1[N];
int fnd(int cor, int x) {
if (cor <= 0)
return 0;
int res = (cor / x) / 2 * x;
if ((cor / x) % 2)
res += cor % x + 1;
return res;
}
ll calc(ll x) {
ll res1 = 0, res2 = 0;
for (int i = 1; i <= k; i++) {
int b1 = fnd(xx1[i], x) - fnd(xx[i] - 1, x),
w1 = (xx1[i] - xx[i] + 1) - b1,
b2 = fnd(yy1[i], x) - fnd(yy[i] - 1, x),
w2 = (yy1[i] - yy[i] + 1) - b2;
int x1 = xx[i] / x, y1 = yy[i] / x;
if (x1 % 2) {
swap(b2, w2);
}
if (y1 % 2) {
swap(b1, w1);
}
if (x1 % 2 == y1 % 2) {
res1 += b1 * b2 + w1 * w2;
res2 += (b1 * w2 + w1 * b2);
} else {
res1 += b1 * w2 + w1 * b2;
res2 += b1 * b2 + w1 * w2;
}
}
ll c1 = (n / x) * (n / x) / 2 * x * x;
ll c2 = n * n - c1;
return min(c1 - res2 + res1, c2 - res1 + res2);
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> xx[i] >> yy[i] >> xx1[i] >> yy1[i];
xx[i]--;
yy[i]--;
xx1[i]--;
yy1[i]--;
}
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
ans = min(ans, calc(i));
if (i != 1)
ans = min(ans, calc(n / i));
}
}
cout << ans;
return 0;
}
/*
*/
Compilation message
chessboard.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
3 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
3900 KB |
Output is correct |
2 |
Correct |
9 ms |
3900 KB |
Output is correct |
3 |
Correct |
19 ms |
4556 KB |
Output is correct |
4 |
Correct |
20 ms |
5624 KB |
Output is correct |
5 |
Correct |
26 ms |
7132 KB |
Output is correct |
6 |
Correct |
16 ms |
7132 KB |
Output is correct |
7 |
Correct |
5 ms |
7132 KB |
Output is correct |
8 |
Correct |
17 ms |
7132 KB |
Output is correct |
9 |
Correct |
40 ms |
8660 KB |
Output is correct |
10 |
Correct |
26 ms |
8660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8660 KB |
Output is correct |
2 |
Correct |
2 ms |
8660 KB |
Output is correct |
3 |
Correct |
3 ms |
8660 KB |
Output is correct |
4 |
Correct |
3 ms |
8660 KB |
Output is correct |
5 |
Correct |
2 ms |
8660 KB |
Output is correct |
6 |
Correct |
2 ms |
8660 KB |
Output is correct |
7 |
Correct |
2 ms |
8660 KB |
Output is correct |
8 |
Correct |
2 ms |
8660 KB |
Output is correct |
9 |
Correct |
2 ms |
8660 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
2 ms |
8660 KB |
Output is correct |
12 |
Correct |
2 ms |
8660 KB |
Output is correct |
13 |
Correct |
3 ms |
8660 KB |
Output is correct |
14 |
Correct |
2 ms |
8660 KB |
Output is correct |
15 |
Correct |
2 ms |
8660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8660 KB |
Output is correct |
2 |
Correct |
2 ms |
8660 KB |
Output is correct |
3 |
Correct |
3 ms |
8660 KB |
Output is correct |
4 |
Correct |
3 ms |
8660 KB |
Output is correct |
5 |
Correct |
2 ms |
8660 KB |
Output is correct |
6 |
Correct |
2 ms |
8660 KB |
Output is correct |
7 |
Correct |
2 ms |
8660 KB |
Output is correct |
8 |
Correct |
2 ms |
8660 KB |
Output is correct |
9 |
Correct |
2 ms |
8660 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
2 ms |
8660 KB |
Output is correct |
12 |
Correct |
2 ms |
8660 KB |
Output is correct |
13 |
Correct |
3 ms |
8660 KB |
Output is correct |
14 |
Correct |
2 ms |
8660 KB |
Output is correct |
15 |
Correct |
2 ms |
8660 KB |
Output is correct |
16 |
Correct |
16 ms |
8660 KB |
Output is correct |
17 |
Correct |
32 ms |
9532 KB |
Output is correct |
18 |
Correct |
53 ms |
11236 KB |
Output is correct |
19 |
Correct |
217 ms |
12460 KB |
Output is correct |
20 |
Correct |
248 ms |
14224 KB |
Output is correct |
21 |
Correct |
37 ms |
15080 KB |
Output is correct |
22 |
Correct |
2 ms |
15080 KB |
Output is correct |
23 |
Correct |
37 ms |
15080 KB |
Output is correct |
24 |
Correct |
50 ms |
17572 KB |
Output is correct |
25 |
Correct |
10 ms |
17572 KB |
Output is correct |
26 |
Correct |
34 ms |
17572 KB |
Output is correct |
27 |
Correct |
51 ms |
18908 KB |
Output is correct |
28 |
Correct |
54 ms |
21184 KB |
Output is correct |
29 |
Correct |
15 ms |
21184 KB |
Output is correct |
30 |
Correct |
3 ms |
21184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
3900 KB |
Output is correct |
2 |
Correct |
9 ms |
3900 KB |
Output is correct |
3 |
Correct |
19 ms |
4556 KB |
Output is correct |
4 |
Correct |
20 ms |
5624 KB |
Output is correct |
5 |
Correct |
26 ms |
7132 KB |
Output is correct |
6 |
Correct |
16 ms |
7132 KB |
Output is correct |
7 |
Correct |
5 ms |
7132 KB |
Output is correct |
8 |
Correct |
17 ms |
7132 KB |
Output is correct |
9 |
Correct |
40 ms |
8660 KB |
Output is correct |
10 |
Correct |
26 ms |
8660 KB |
Output is correct |
11 |
Correct |
2 ms |
8660 KB |
Output is correct |
12 |
Correct |
2 ms |
8660 KB |
Output is correct |
13 |
Correct |
3 ms |
8660 KB |
Output is correct |
14 |
Correct |
3 ms |
8660 KB |
Output is correct |
15 |
Correct |
2 ms |
8660 KB |
Output is correct |
16 |
Correct |
2 ms |
8660 KB |
Output is correct |
17 |
Correct |
2 ms |
8660 KB |
Output is correct |
18 |
Correct |
2 ms |
8660 KB |
Output is correct |
19 |
Correct |
2 ms |
8660 KB |
Output is correct |
20 |
Correct |
2 ms |
8660 KB |
Output is correct |
21 |
Correct |
2 ms |
8660 KB |
Output is correct |
22 |
Correct |
2 ms |
8660 KB |
Output is correct |
23 |
Correct |
3 ms |
8660 KB |
Output is correct |
24 |
Correct |
2 ms |
8660 KB |
Output is correct |
25 |
Correct |
2 ms |
8660 KB |
Output is correct |
26 |
Correct |
16 ms |
8660 KB |
Output is correct |
27 |
Correct |
32 ms |
9532 KB |
Output is correct |
28 |
Correct |
53 ms |
11236 KB |
Output is correct |
29 |
Correct |
217 ms |
12460 KB |
Output is correct |
30 |
Correct |
248 ms |
14224 KB |
Output is correct |
31 |
Correct |
37 ms |
15080 KB |
Output is correct |
32 |
Correct |
2 ms |
15080 KB |
Output is correct |
33 |
Correct |
37 ms |
15080 KB |
Output is correct |
34 |
Correct |
50 ms |
17572 KB |
Output is correct |
35 |
Correct |
10 ms |
17572 KB |
Output is correct |
36 |
Correct |
34 ms |
17572 KB |
Output is correct |
37 |
Correct |
51 ms |
18908 KB |
Output is correct |
38 |
Correct |
54 ms |
21184 KB |
Output is correct |
39 |
Correct |
15 ms |
21184 KB |
Output is correct |
40 |
Correct |
3 ms |
21184 KB |
Output is correct |
41 |
Correct |
183 ms |
21184 KB |
Output is correct |
42 |
Correct |
56 ms |
21184 KB |
Output is correct |
43 |
Correct |
106 ms |
21184 KB |
Output is correct |
44 |
Correct |
57 ms |
23012 KB |
Output is correct |
45 |
Correct |
44 ms |
24148 KB |
Output is correct |
46 |
Correct |
206 ms |
24148 KB |
Output is correct |
47 |
Correct |
39 ms |
24148 KB |
Output is correct |
48 |
Correct |
81 ms |
24148 KB |
Output is correct |
49 |
Correct |
50 ms |
24148 KB |
Output is correct |
50 |
Correct |
976 ms |
24148 KB |
Output is correct |
51 |
Correct |
1051 ms |
24148 KB |
Output is correct |
52 |
Correct |
970 ms |
24148 KB |
Output is correct |
53 |
Correct |
1042 ms |
24148 KB |
Output is correct |
54 |
Correct |
976 ms |
24148 KB |
Output is correct |
55 |
Correct |
1071 ms |
24296 KB |
Output is correct |
56 |
Correct |
915 ms |
24296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
3 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
30 ms |
3900 KB |
Output is correct |
10 |
Correct |
9 ms |
3900 KB |
Output is correct |
11 |
Correct |
19 ms |
4556 KB |
Output is correct |
12 |
Correct |
20 ms |
5624 KB |
Output is correct |
13 |
Correct |
26 ms |
7132 KB |
Output is correct |
14 |
Correct |
16 ms |
7132 KB |
Output is correct |
15 |
Correct |
5 ms |
7132 KB |
Output is correct |
16 |
Correct |
17 ms |
7132 KB |
Output is correct |
17 |
Correct |
40 ms |
8660 KB |
Output is correct |
18 |
Correct |
26 ms |
8660 KB |
Output is correct |
19 |
Correct |
2 ms |
8660 KB |
Output is correct |
20 |
Correct |
2 ms |
8660 KB |
Output is correct |
21 |
Correct |
3 ms |
8660 KB |
Output is correct |
22 |
Correct |
3 ms |
8660 KB |
Output is correct |
23 |
Correct |
2 ms |
8660 KB |
Output is correct |
24 |
Correct |
2 ms |
8660 KB |
Output is correct |
25 |
Correct |
2 ms |
8660 KB |
Output is correct |
26 |
Correct |
2 ms |
8660 KB |
Output is correct |
27 |
Correct |
2 ms |
8660 KB |
Output is correct |
28 |
Correct |
2 ms |
8660 KB |
Output is correct |
29 |
Correct |
2 ms |
8660 KB |
Output is correct |
30 |
Correct |
2 ms |
8660 KB |
Output is correct |
31 |
Correct |
3 ms |
8660 KB |
Output is correct |
32 |
Correct |
2 ms |
8660 KB |
Output is correct |
33 |
Correct |
2 ms |
8660 KB |
Output is correct |
34 |
Correct |
16 ms |
8660 KB |
Output is correct |
35 |
Correct |
32 ms |
9532 KB |
Output is correct |
36 |
Correct |
53 ms |
11236 KB |
Output is correct |
37 |
Correct |
217 ms |
12460 KB |
Output is correct |
38 |
Correct |
248 ms |
14224 KB |
Output is correct |
39 |
Correct |
37 ms |
15080 KB |
Output is correct |
40 |
Correct |
2 ms |
15080 KB |
Output is correct |
41 |
Correct |
37 ms |
15080 KB |
Output is correct |
42 |
Correct |
50 ms |
17572 KB |
Output is correct |
43 |
Correct |
10 ms |
17572 KB |
Output is correct |
44 |
Correct |
34 ms |
17572 KB |
Output is correct |
45 |
Correct |
51 ms |
18908 KB |
Output is correct |
46 |
Correct |
54 ms |
21184 KB |
Output is correct |
47 |
Correct |
15 ms |
21184 KB |
Output is correct |
48 |
Correct |
3 ms |
21184 KB |
Output is correct |
49 |
Correct |
183 ms |
21184 KB |
Output is correct |
50 |
Correct |
56 ms |
21184 KB |
Output is correct |
51 |
Correct |
106 ms |
21184 KB |
Output is correct |
52 |
Correct |
57 ms |
23012 KB |
Output is correct |
53 |
Correct |
44 ms |
24148 KB |
Output is correct |
54 |
Correct |
206 ms |
24148 KB |
Output is correct |
55 |
Correct |
39 ms |
24148 KB |
Output is correct |
56 |
Correct |
81 ms |
24148 KB |
Output is correct |
57 |
Correct |
50 ms |
24148 KB |
Output is correct |
58 |
Correct |
976 ms |
24148 KB |
Output is correct |
59 |
Correct |
1051 ms |
24148 KB |
Output is correct |
60 |
Correct |
970 ms |
24148 KB |
Output is correct |
61 |
Correct |
1042 ms |
24148 KB |
Output is correct |
62 |
Correct |
976 ms |
24148 KB |
Output is correct |
63 |
Correct |
1071 ms |
24296 KB |
Output is correct |
64 |
Correct |
915 ms |
24296 KB |
Output is correct |
65 |
Correct |
2 ms |
24296 KB |
Output is correct |
66 |
Correct |
2 ms |
24296 KB |
Output is correct |
67 |
Correct |
1020 ms |
26344 KB |
Output is correct |
68 |
Correct |
1008 ms |
28576 KB |
Output is correct |
69 |
Correct |
855 ms |
30124 KB |
Output is correct |
70 |
Correct |
977 ms |
32628 KB |
Output is correct |
71 |
Correct |
962 ms |
34676 KB |
Output is correct |
72 |
Correct |
919 ms |
36680 KB |
Output is correct |
73 |
Correct |
904 ms |
38528 KB |
Output is correct |
74 |
Correct |
990 ms |
38856 KB |
Output is correct |
75 |
Correct |
934 ms |
38856 KB |
Output is correct |
76 |
Correct |
997 ms |
38856 KB |
Output is correct |
77 |
Correct |
151 ms |
39004 KB |
Output is correct |
78 |
Correct |
54 ms |
39004 KB |
Output is correct |
79 |
Correct |
106 ms |
39004 KB |
Output is correct |
80 |
Correct |
160 ms |
39004 KB |
Output is correct |
81 |
Correct |
99 ms |
39004 KB |
Output is correct |
82 |
Correct |
91 ms |
39004 KB |
Output is correct |
83 |
Correct |
63 ms |
39004 KB |
Output is correct |
84 |
Correct |
589 ms |
39004 KB |
Output is correct |
85 |
Correct |
1056 ms |
39056 KB |
Output is correct |
86 |
Correct |
3 ms |
39056 KB |
Output is correct |
87 |
Correct |
2 ms |
39056 KB |
Output is correct |
88 |
Correct |
1049 ms |
39056 KB |
Output is correct |
89 |
Correct |
198 ms |
39056 KB |
Output is correct |
90 |
Correct |
2 ms |
39056 KB |
Output is correct |