#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
//#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug(...)
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define fillchar(a, s) memset((a), (s), sizeof(a))
template<class T>
void setmin (T &a, T b) {
if (b < a) {
a = b;
}
}
ll N, K, D;
ll X1[MAXN], X2[MAXN], Y1[MAXN], Y2[MAXN];
ll totrect;
ll delta (ll xmx, ll ymx) {
if (xmx == 0 || ymx == 0) {
return 0;
}
//which one is covered?
ll xbound = xmx / D, ybound = ymx / D;
//0 <= x <= xbound, 0 <= y <= ybound -- how many ways x + y is even?
ll xodd = xbound >> 1, yodd = ybound >> 1, xeven = xbound - xodd, yeven = ybound - yodd;
ll ans = (xeven * yeven + xodd * yodd) * D * D;
ll xlen = xmx - xbound * D, ylen = ymx - ybound * D;
if (xlen) {
//one
//0 <= y < ybound * D
if ((xbound & 1) == 0) {
//starts with white
ans += yeven * D * xlen;
} else {
//starts with black
ans += yodd * D * xlen;
}
//both
if (ylen) {
if ((xbound & 1) == (ybound & 1)) {
ans += xlen * ylen;
}
}
}
if (ylen) {
if (ybound % 2 == 0) {
ans += xeven * D * ylen;
} else {
ans += xodd * D * ylen;
}
}
return ans;
}
#warning int overflow!
ll go() {
ll ans = (N / D) * (N / D) / 2 * D * D - totrect;
for (ll i = 0; i < K; i++) {
ans += (delta(X1[i], Y1[i]) + delta(X2[i], Y2[i]) - delta(X1[i], Y2[i]) - delta(X2[i], Y1[i])) << 1;
}
return min(N * N - ans, ans);
}
int main() {
scanf("%lld %lld", &N, &K);
for (ll i = 0; i < K; i++) {
scanf("%lld %lld %lld %lld", &X1[i], &Y1[i], &X2[i], &Y2[i]);
X1[i]--;
Y1[i]--;
totrect += (X2[i] - X1[i]) * (Y2[i] - Y1[i]);
}
ll ans = ll(N) * N;
for (D = 1; D < N; D++) {
if (N % D == 0) {
setmin(ans, go());
}
}
printf("%lld\n", ans);
}
Compilation message
chessboard.cpp:68:2: warning: #warning int overflow! [-Wcpp]
#warning int overflow!
^~~~~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &N, &K);
~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld", &X1[i], &Y1[i], &X2[i], &Y2[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
356 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
2 ms |
628 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
2 ms |
628 KB |
Output is correct |
8 |
Correct |
4 ms |
628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2512 KB |
Output is correct |
2 |
Correct |
21 ms |
2512 KB |
Output is correct |
3 |
Correct |
45 ms |
2512 KB |
Output is correct |
4 |
Correct |
28 ms |
2512 KB |
Output is correct |
5 |
Correct |
48 ms |
2556 KB |
Output is correct |
6 |
Correct |
30 ms |
2556 KB |
Output is correct |
7 |
Correct |
9 ms |
2556 KB |
Output is correct |
8 |
Correct |
24 ms |
2556 KB |
Output is correct |
9 |
Correct |
59 ms |
3484 KB |
Output is correct |
10 |
Correct |
32 ms |
3484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3484 KB |
Output is correct |
2 |
Correct |
3 ms |
3484 KB |
Output is correct |
3 |
Correct |
2 ms |
3484 KB |
Output is correct |
4 |
Correct |
4 ms |
3484 KB |
Output is correct |
5 |
Correct |
3 ms |
3484 KB |
Output is correct |
6 |
Correct |
3 ms |
3484 KB |
Output is correct |
7 |
Correct |
3 ms |
3484 KB |
Output is correct |
8 |
Correct |
4 ms |
3484 KB |
Output is correct |
9 |
Correct |
3 ms |
3484 KB |
Output is correct |
10 |
Correct |
3 ms |
3484 KB |
Output is correct |
11 |
Correct |
3 ms |
3484 KB |
Output is correct |
12 |
Correct |
3 ms |
3484 KB |
Output is correct |
13 |
Correct |
3 ms |
3484 KB |
Output is correct |
14 |
Correct |
3 ms |
3484 KB |
Output is correct |
15 |
Correct |
4 ms |
3484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3484 KB |
Output is correct |
2 |
Correct |
3 ms |
3484 KB |
Output is correct |
3 |
Correct |
2 ms |
3484 KB |
Output is correct |
4 |
Correct |
4 ms |
3484 KB |
Output is correct |
5 |
Correct |
3 ms |
3484 KB |
Output is correct |
6 |
Correct |
3 ms |
3484 KB |
Output is correct |
7 |
Correct |
3 ms |
3484 KB |
Output is correct |
8 |
Correct |
4 ms |
3484 KB |
Output is correct |
9 |
Correct |
3 ms |
3484 KB |
Output is correct |
10 |
Correct |
3 ms |
3484 KB |
Output is correct |
11 |
Correct |
3 ms |
3484 KB |
Output is correct |
12 |
Correct |
3 ms |
3484 KB |
Output is correct |
13 |
Correct |
3 ms |
3484 KB |
Output is correct |
14 |
Correct |
3 ms |
3484 KB |
Output is correct |
15 |
Correct |
4 ms |
3484 KB |
Output is correct |
16 |
Correct |
26 ms |
3484 KB |
Output is correct |
17 |
Correct |
48 ms |
3484 KB |
Output is correct |
18 |
Correct |
83 ms |
3708 KB |
Output is correct |
19 |
Correct |
406 ms |
3708 KB |
Output is correct |
20 |
Correct |
435 ms |
3708 KB |
Output is correct |
21 |
Correct |
46 ms |
3708 KB |
Output is correct |
22 |
Correct |
4 ms |
3708 KB |
Output is correct |
23 |
Correct |
61 ms |
3708 KB |
Output is correct |
24 |
Correct |
79 ms |
3708 KB |
Output is correct |
25 |
Correct |
14 ms |
3708 KB |
Output is correct |
26 |
Correct |
50 ms |
3708 KB |
Output is correct |
27 |
Correct |
76 ms |
3708 KB |
Output is correct |
28 |
Correct |
83 ms |
3708 KB |
Output is correct |
29 |
Correct |
35 ms |
3708 KB |
Output is correct |
30 |
Correct |
5 ms |
3708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2512 KB |
Output is correct |
2 |
Correct |
21 ms |
2512 KB |
Output is correct |
3 |
Correct |
45 ms |
2512 KB |
Output is correct |
4 |
Correct |
28 ms |
2512 KB |
Output is correct |
5 |
Correct |
48 ms |
2556 KB |
Output is correct |
6 |
Correct |
30 ms |
2556 KB |
Output is correct |
7 |
Correct |
9 ms |
2556 KB |
Output is correct |
8 |
Correct |
24 ms |
2556 KB |
Output is correct |
9 |
Correct |
59 ms |
3484 KB |
Output is correct |
10 |
Correct |
32 ms |
3484 KB |
Output is correct |
11 |
Correct |
3 ms |
3484 KB |
Output is correct |
12 |
Correct |
3 ms |
3484 KB |
Output is correct |
13 |
Correct |
2 ms |
3484 KB |
Output is correct |
14 |
Correct |
4 ms |
3484 KB |
Output is correct |
15 |
Correct |
3 ms |
3484 KB |
Output is correct |
16 |
Correct |
3 ms |
3484 KB |
Output is correct |
17 |
Correct |
3 ms |
3484 KB |
Output is correct |
18 |
Correct |
4 ms |
3484 KB |
Output is correct |
19 |
Correct |
3 ms |
3484 KB |
Output is correct |
20 |
Correct |
3 ms |
3484 KB |
Output is correct |
21 |
Correct |
3 ms |
3484 KB |
Output is correct |
22 |
Correct |
3 ms |
3484 KB |
Output is correct |
23 |
Correct |
3 ms |
3484 KB |
Output is correct |
24 |
Correct |
3 ms |
3484 KB |
Output is correct |
25 |
Correct |
4 ms |
3484 KB |
Output is correct |
26 |
Correct |
26 ms |
3484 KB |
Output is correct |
27 |
Correct |
48 ms |
3484 KB |
Output is correct |
28 |
Correct |
83 ms |
3708 KB |
Output is correct |
29 |
Correct |
406 ms |
3708 KB |
Output is correct |
30 |
Correct |
435 ms |
3708 KB |
Output is correct |
31 |
Correct |
46 ms |
3708 KB |
Output is correct |
32 |
Correct |
4 ms |
3708 KB |
Output is correct |
33 |
Correct |
61 ms |
3708 KB |
Output is correct |
34 |
Correct |
79 ms |
3708 KB |
Output is correct |
35 |
Correct |
14 ms |
3708 KB |
Output is correct |
36 |
Correct |
50 ms |
3708 KB |
Output is correct |
37 |
Correct |
76 ms |
3708 KB |
Output is correct |
38 |
Correct |
83 ms |
3708 KB |
Output is correct |
39 |
Correct |
35 ms |
3708 KB |
Output is correct |
40 |
Correct |
5 ms |
3708 KB |
Output is correct |
41 |
Correct |
325 ms |
3708 KB |
Output is correct |
42 |
Correct |
89 ms |
3708 KB |
Output is correct |
43 |
Correct |
180 ms |
3708 KB |
Output is correct |
44 |
Correct |
91 ms |
3708 KB |
Output is correct |
45 |
Correct |
118 ms |
3708 KB |
Output is correct |
46 |
Correct |
390 ms |
3708 KB |
Output is correct |
47 |
Correct |
55 ms |
3708 KB |
Output is correct |
48 |
Correct |
143 ms |
3708 KB |
Output is correct |
49 |
Correct |
87 ms |
3708 KB |
Output is correct |
50 |
Correct |
1789 ms |
3708 KB |
Output is correct |
51 |
Correct |
1965 ms |
3708 KB |
Output is correct |
52 |
Correct |
1787 ms |
5756 KB |
Output is correct |
53 |
Correct |
1843 ms |
8152 KB |
Output is correct |
54 |
Correct |
1771 ms |
10140 KB |
Output is correct |
55 |
Correct |
1927 ms |
12788 KB |
Output is correct |
56 |
Correct |
1694 ms |
14472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
356 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
2 ms |
628 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
2 ms |
628 KB |
Output is correct |
8 |
Correct |
4 ms |
628 KB |
Output is correct |
9 |
Correct |
47 ms |
2512 KB |
Output is correct |
10 |
Correct |
21 ms |
2512 KB |
Output is correct |
11 |
Correct |
45 ms |
2512 KB |
Output is correct |
12 |
Correct |
28 ms |
2512 KB |
Output is correct |
13 |
Correct |
48 ms |
2556 KB |
Output is correct |
14 |
Correct |
30 ms |
2556 KB |
Output is correct |
15 |
Correct |
9 ms |
2556 KB |
Output is correct |
16 |
Correct |
24 ms |
2556 KB |
Output is correct |
17 |
Correct |
59 ms |
3484 KB |
Output is correct |
18 |
Correct |
32 ms |
3484 KB |
Output is correct |
19 |
Correct |
3 ms |
3484 KB |
Output is correct |
20 |
Correct |
3 ms |
3484 KB |
Output is correct |
21 |
Correct |
2 ms |
3484 KB |
Output is correct |
22 |
Correct |
4 ms |
3484 KB |
Output is correct |
23 |
Correct |
3 ms |
3484 KB |
Output is correct |
24 |
Correct |
3 ms |
3484 KB |
Output is correct |
25 |
Correct |
3 ms |
3484 KB |
Output is correct |
26 |
Correct |
4 ms |
3484 KB |
Output is correct |
27 |
Correct |
3 ms |
3484 KB |
Output is correct |
28 |
Correct |
3 ms |
3484 KB |
Output is correct |
29 |
Correct |
3 ms |
3484 KB |
Output is correct |
30 |
Correct |
3 ms |
3484 KB |
Output is correct |
31 |
Correct |
3 ms |
3484 KB |
Output is correct |
32 |
Correct |
3 ms |
3484 KB |
Output is correct |
33 |
Correct |
4 ms |
3484 KB |
Output is correct |
34 |
Correct |
26 ms |
3484 KB |
Output is correct |
35 |
Correct |
48 ms |
3484 KB |
Output is correct |
36 |
Correct |
83 ms |
3708 KB |
Output is correct |
37 |
Correct |
406 ms |
3708 KB |
Output is correct |
38 |
Correct |
435 ms |
3708 KB |
Output is correct |
39 |
Correct |
46 ms |
3708 KB |
Output is correct |
40 |
Correct |
4 ms |
3708 KB |
Output is correct |
41 |
Correct |
61 ms |
3708 KB |
Output is correct |
42 |
Correct |
79 ms |
3708 KB |
Output is correct |
43 |
Correct |
14 ms |
3708 KB |
Output is correct |
44 |
Correct |
50 ms |
3708 KB |
Output is correct |
45 |
Correct |
76 ms |
3708 KB |
Output is correct |
46 |
Correct |
83 ms |
3708 KB |
Output is correct |
47 |
Correct |
35 ms |
3708 KB |
Output is correct |
48 |
Correct |
5 ms |
3708 KB |
Output is correct |
49 |
Correct |
325 ms |
3708 KB |
Output is correct |
50 |
Correct |
89 ms |
3708 KB |
Output is correct |
51 |
Correct |
180 ms |
3708 KB |
Output is correct |
52 |
Correct |
91 ms |
3708 KB |
Output is correct |
53 |
Correct |
118 ms |
3708 KB |
Output is correct |
54 |
Correct |
390 ms |
3708 KB |
Output is correct |
55 |
Correct |
55 ms |
3708 KB |
Output is correct |
56 |
Correct |
143 ms |
3708 KB |
Output is correct |
57 |
Correct |
87 ms |
3708 KB |
Output is correct |
58 |
Correct |
1789 ms |
3708 KB |
Output is correct |
59 |
Correct |
1965 ms |
3708 KB |
Output is correct |
60 |
Correct |
1787 ms |
5756 KB |
Output is correct |
61 |
Correct |
1843 ms |
8152 KB |
Output is correct |
62 |
Correct |
1771 ms |
10140 KB |
Output is correct |
63 |
Correct |
1927 ms |
12788 KB |
Output is correct |
64 |
Correct |
1694 ms |
14472 KB |
Output is correct |
65 |
Correct |
3 ms |
14472 KB |
Output is correct |
66 |
Correct |
2 ms |
14472 KB |
Output is correct |
67 |
Correct |
1878 ms |
17052 KB |
Output is correct |
68 |
Correct |
1881 ms |
19244 KB |
Output is correct |
69 |
Correct |
1572 ms |
20960 KB |
Output is correct |
70 |
Correct |
1910 ms |
23304 KB |
Output is correct |
71 |
Correct |
1805 ms |
25456 KB |
Output is correct |
72 |
Correct |
1704 ms |
27548 KB |
Output is correct |
73 |
Correct |
1677 ms |
29524 KB |
Output is correct |
74 |
Correct |
1812 ms |
31940 KB |
Output is correct |
75 |
Correct |
1759 ms |
33908 KB |
Output is correct |
76 |
Correct |
1885 ms |
36396 KB |
Output is correct |
77 |
Correct |
282 ms |
38912 KB |
Output is correct |
78 |
Correct |
92 ms |
40776 KB |
Output is correct |
79 |
Correct |
203 ms |
42616 KB |
Output is correct |
80 |
Correct |
204 ms |
44860 KB |
Output is correct |
81 |
Correct |
185 ms |
46600 KB |
Output is correct |
82 |
Correct |
151 ms |
49160 KB |
Output is correct |
83 |
Correct |
107 ms |
51060 KB |
Output is correct |
84 |
Correct |
1160 ms |
53568 KB |
Output is correct |
85 |
Execution timed out |
2060 ms |
56148 KB |
Time limit exceeded |
86 |
Halted |
0 ms |
0 KB |
- |