#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "../../../debug.h"
#else
#define debug(...) void(23)
#endif
i64 get(i64 a, i64 b, i64 len) {
i64 ans = 0;
i64 ma = a % (2 * len);
i64 mb = b % (2 * len);
i64 da = a / (2 * len);
i64 db = b / (2 * len);
ans += da * db * len * len * 2;
ans += mb * da * len;
ans += ma * db * len;
ans += std::max(0LL, mb - len) * std::min(len, ma);
ans += std::max(0LL, ma - len) * std::min(len, mb);
debug(a, b, len, ans);
return ans;
}
i64 count_good(i64 a, i64 b, i64 c, i64 d, i64 len) {
return get(c, d, len)
- get(a, d, len)
- get(c, b, len)
+ get(a, b, len);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 N, K;
std::cin >> N >> K;
std::vector<i64> A(K), B(K), C(K), D(K);
for (int i = 0; i < K; ++i) {
std::cin >> A[i] >> B[i] >> C[i] >> D[i];
--A[i], --B[i];
}
i64 ans = 2 * N * N;
for (i64 k = 1; k < N; ++k) {
if (N % k != 0) {
continue;
}
i64 now = N * N - count_good(0, 0, N, N, k);
for (int i = 0; i < K; ++i) {
i64 x = count_good(A[i], B[i], C[i], D[i], k);
debug(A[i], B[i], C[i], D[i], x);
now -= ((C[i] - A[i]) * (D[i] - B[i]) - x);
now += x;
}
debug(k, now);
ans = std::min(ans, std::min(now, N * N - now));
}
std::cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2384 KB |
Output is correct |
2 |
Correct |
4 ms |
848 KB |
Output is correct |
3 |
Correct |
9 ms |
1616 KB |
Output is correct |
4 |
Correct |
11 ms |
1872 KB |
Output is correct |
5 |
Correct |
13 ms |
2128 KB |
Output is correct |
6 |
Correct |
10 ms |
2128 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
8 ms |
1360 KB |
Output is correct |
9 |
Correct |
22 ms |
3288 KB |
Output is correct |
10 |
Correct |
12 ms |
1872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
1104 KB |
Output is correct |
17 |
Correct |
19 ms |
3104 KB |
Output is correct |
18 |
Correct |
32 ms |
3408 KB |
Output is correct |
19 |
Correct |
91 ms |
3408 KB |
Output is correct |
20 |
Correct |
95 ms |
3576 KB |
Output is correct |
21 |
Correct |
18 ms |
2896 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
15 ms |
1616 KB |
Output is correct |
24 |
Correct |
25 ms |
3648 KB |
Output is correct |
25 |
Correct |
3 ms |
592 KB |
Output is correct |
26 |
Correct |
14 ms |
2128 KB |
Output is correct |
27 |
Correct |
20 ms |
2596 KB |
Output is correct |
28 |
Correct |
26 ms |
3656 KB |
Output is correct |
29 |
Correct |
8 ms |
1360 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2384 KB |
Output is correct |
2 |
Correct |
4 ms |
848 KB |
Output is correct |
3 |
Correct |
9 ms |
1616 KB |
Output is correct |
4 |
Correct |
11 ms |
1872 KB |
Output is correct |
5 |
Correct |
13 ms |
2128 KB |
Output is correct |
6 |
Correct |
10 ms |
2128 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
8 ms |
1360 KB |
Output is correct |
9 |
Correct |
22 ms |
3288 KB |
Output is correct |
10 |
Correct |
12 ms |
1872 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
504 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
8 ms |
1104 KB |
Output is correct |
27 |
Correct |
19 ms |
3104 KB |
Output is correct |
28 |
Correct |
32 ms |
3408 KB |
Output is correct |
29 |
Correct |
91 ms |
3408 KB |
Output is correct |
30 |
Correct |
95 ms |
3576 KB |
Output is correct |
31 |
Correct |
18 ms |
2896 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
15 ms |
1616 KB |
Output is correct |
34 |
Correct |
25 ms |
3648 KB |
Output is correct |
35 |
Correct |
3 ms |
592 KB |
Output is correct |
36 |
Correct |
14 ms |
2128 KB |
Output is correct |
37 |
Correct |
20 ms |
2596 KB |
Output is correct |
38 |
Correct |
26 ms |
3656 KB |
Output is correct |
39 |
Correct |
8 ms |
1360 KB |
Output is correct |
40 |
Correct |
2 ms |
336 KB |
Output is correct |
41 |
Correct |
59 ms |
2896 KB |
Output is correct |
42 |
Correct |
26 ms |
3152 KB |
Output is correct |
43 |
Correct |
44 ms |
3408 KB |
Output is correct |
44 |
Correct |
26 ms |
3152 KB |
Output is correct |
45 |
Correct |
24 ms |
3408 KB |
Output is correct |
46 |
Correct |
67 ms |
3344 KB |
Output is correct |
47 |
Correct |
34 ms |
3152 KB |
Output is correct |
48 |
Correct |
39 ms |
3912 KB |
Output is correct |
49 |
Correct |
28 ms |
2896 KB |
Output is correct |
50 |
Correct |
276 ms |
3876 KB |
Output is correct |
51 |
Correct |
284 ms |
5712 KB |
Output is correct |
52 |
Correct |
277 ms |
3152 KB |
Output is correct |
53 |
Correct |
279 ms |
3408 KB |
Output is correct |
54 |
Correct |
287 ms |
5200 KB |
Output is correct |
55 |
Correct |
281 ms |
3408 KB |
Output is correct |
56 |
Correct |
257 ms |
3152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
15 ms |
2384 KB |
Output is correct |
10 |
Correct |
4 ms |
848 KB |
Output is correct |
11 |
Correct |
9 ms |
1616 KB |
Output is correct |
12 |
Correct |
11 ms |
1872 KB |
Output is correct |
13 |
Correct |
13 ms |
2128 KB |
Output is correct |
14 |
Correct |
10 ms |
2128 KB |
Output is correct |
15 |
Correct |
2 ms |
592 KB |
Output is correct |
16 |
Correct |
8 ms |
1360 KB |
Output is correct |
17 |
Correct |
22 ms |
3288 KB |
Output is correct |
18 |
Correct |
12 ms |
1872 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
504 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
504 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
8 ms |
1104 KB |
Output is correct |
35 |
Correct |
19 ms |
3104 KB |
Output is correct |
36 |
Correct |
32 ms |
3408 KB |
Output is correct |
37 |
Correct |
91 ms |
3408 KB |
Output is correct |
38 |
Correct |
95 ms |
3576 KB |
Output is correct |
39 |
Correct |
18 ms |
2896 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
15 ms |
1616 KB |
Output is correct |
42 |
Correct |
25 ms |
3648 KB |
Output is correct |
43 |
Correct |
3 ms |
592 KB |
Output is correct |
44 |
Correct |
14 ms |
2128 KB |
Output is correct |
45 |
Correct |
20 ms |
2596 KB |
Output is correct |
46 |
Correct |
26 ms |
3656 KB |
Output is correct |
47 |
Correct |
8 ms |
1360 KB |
Output is correct |
48 |
Correct |
2 ms |
336 KB |
Output is correct |
49 |
Correct |
59 ms |
2896 KB |
Output is correct |
50 |
Correct |
26 ms |
3152 KB |
Output is correct |
51 |
Correct |
44 ms |
3408 KB |
Output is correct |
52 |
Correct |
26 ms |
3152 KB |
Output is correct |
53 |
Correct |
24 ms |
3408 KB |
Output is correct |
54 |
Correct |
67 ms |
3344 KB |
Output is correct |
55 |
Correct |
34 ms |
3152 KB |
Output is correct |
56 |
Correct |
39 ms |
3912 KB |
Output is correct |
57 |
Correct |
28 ms |
2896 KB |
Output is correct |
58 |
Correct |
276 ms |
3876 KB |
Output is correct |
59 |
Correct |
284 ms |
5712 KB |
Output is correct |
60 |
Correct |
277 ms |
3152 KB |
Output is correct |
61 |
Correct |
279 ms |
3408 KB |
Output is correct |
62 |
Correct |
287 ms |
5200 KB |
Output is correct |
63 |
Correct |
281 ms |
3408 KB |
Output is correct |
64 |
Correct |
257 ms |
3152 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
273 ms |
3936 KB |
Output is correct |
68 |
Correct |
286 ms |
3152 KB |
Output is correct |
69 |
Correct |
242 ms |
4256 KB |
Output is correct |
70 |
Correct |
253 ms |
4688 KB |
Output is correct |
71 |
Correct |
240 ms |
3152 KB |
Output is correct |
72 |
Correct |
257 ms |
3156 KB |
Output is correct |
73 |
Correct |
246 ms |
3428 KB |
Output is correct |
74 |
Correct |
268 ms |
3152 KB |
Output is correct |
75 |
Correct |
295 ms |
3924 KB |
Output is correct |
76 |
Correct |
270 ms |
4316 KB |
Output is correct |
77 |
Correct |
57 ms |
5704 KB |
Output is correct |
78 |
Correct |
29 ms |
3312 KB |
Output is correct |
79 |
Correct |
40 ms |
4372 KB |
Output is correct |
80 |
Correct |
46 ms |
4476 KB |
Output is correct |
81 |
Correct |
61 ms |
2896 KB |
Output is correct |
82 |
Correct |
39 ms |
3408 KB |
Output is correct |
83 |
Correct |
51 ms |
5060 KB |
Output is correct |
84 |
Correct |
186 ms |
5784 KB |
Output is correct |
85 |
Correct |
315 ms |
4848 KB |
Output is correct |
86 |
Correct |
2 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
500 KB |
Output is correct |
88 |
Correct |
323 ms |
3568 KB |
Output is correct |
89 |
Correct |
62 ms |
1496 KB |
Output is correct |
90 |
Correct |
1 ms |
336 KB |
Output is correct |