#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int32_t main() {
int N, K; cin >> N >> K;
int ans = N * N;
array<int, 4> a[K];
for(auto &[i, j, k, l] : a)
cin >> i >> j >> k >> l;
for(int s = 1; s < N; ++s) if(!(N % s)) {
#define c(V) (s * ((V) / (2 * s)) + min(s, (V) % (2 * s)))
int cost = c(N) * (N - c(N)) + c(N) * (N - c(N));
for(auto [i, j, k, l] : a) {
int u = k - i + 1, x = c(k) - c(i - 1);
int v = l - j + 1, y = c(l) - c(j - 1);
cost += 2 * (x * y + (u - x) * (v - y)) - u * v;
}
ans = min(ans, min(cost, N * N - cost));
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
2364 KB |
Output is correct |
2 |
Correct |
16 ms |
852 KB |
Output is correct |
3 |
Correct |
42 ms |
1620 KB |
Output is correct |
4 |
Correct |
42 ms |
1748 KB |
Output is correct |
5 |
Correct |
55 ms |
2072 KB |
Output is correct |
6 |
Correct |
41 ms |
1396 KB |
Output is correct |
7 |
Correct |
8 ms |
596 KB |
Output is correct |
8 |
Correct |
36 ms |
1492 KB |
Output is correct |
9 |
Correct |
90 ms |
3124 KB |
Output is correct |
10 |
Correct |
52 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
24 ms |
1204 KB |
Output is correct |
17 |
Correct |
67 ms |
2996 KB |
Output is correct |
18 |
Correct |
83 ms |
3440 KB |
Output is correct |
19 |
Correct |
117 ms |
3176 KB |
Output is correct |
20 |
Correct |
130 ms |
3492 KB |
Output is correct |
21 |
Correct |
65 ms |
2936 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
40 ms |
1728 KB |
Output is correct |
24 |
Correct |
75 ms |
3220 KB |
Output is correct |
25 |
Correct |
10 ms |
596 KB |
Output is correct |
26 |
Correct |
47 ms |
2132 KB |
Output is correct |
27 |
Correct |
60 ms |
2516 KB |
Output is correct |
28 |
Correct |
79 ms |
3388 KB |
Output is correct |
29 |
Correct |
27 ms |
1364 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
2364 KB |
Output is correct |
2 |
Correct |
16 ms |
852 KB |
Output is correct |
3 |
Correct |
42 ms |
1620 KB |
Output is correct |
4 |
Correct |
42 ms |
1748 KB |
Output is correct |
5 |
Correct |
55 ms |
2072 KB |
Output is correct |
6 |
Correct |
41 ms |
1396 KB |
Output is correct |
7 |
Correct |
8 ms |
596 KB |
Output is correct |
8 |
Correct |
36 ms |
1492 KB |
Output is correct |
9 |
Correct |
90 ms |
3124 KB |
Output is correct |
10 |
Correct |
52 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
304 KB |
Output is correct |
26 |
Correct |
24 ms |
1204 KB |
Output is correct |
27 |
Correct |
67 ms |
2996 KB |
Output is correct |
28 |
Correct |
83 ms |
3440 KB |
Output is correct |
29 |
Correct |
117 ms |
3176 KB |
Output is correct |
30 |
Correct |
130 ms |
3492 KB |
Output is correct |
31 |
Correct |
65 ms |
2936 KB |
Output is correct |
32 |
Correct |
1 ms |
304 KB |
Output is correct |
33 |
Correct |
40 ms |
1728 KB |
Output is correct |
34 |
Correct |
75 ms |
3220 KB |
Output is correct |
35 |
Correct |
10 ms |
596 KB |
Output is correct |
36 |
Correct |
47 ms |
2132 KB |
Output is correct |
37 |
Correct |
60 ms |
2516 KB |
Output is correct |
38 |
Correct |
79 ms |
3388 KB |
Output is correct |
39 |
Correct |
27 ms |
1364 KB |
Output is correct |
40 |
Correct |
3 ms |
340 KB |
Output is correct |
41 |
Correct |
132 ms |
2976 KB |
Output is correct |
42 |
Correct |
103 ms |
3340 KB |
Output is correct |
43 |
Correct |
107 ms |
2900 KB |
Output is correct |
44 |
Correct |
98 ms |
3252 KB |
Output is correct |
45 |
Correct |
105 ms |
3412 KB |
Output is correct |
46 |
Correct |
147 ms |
3284 KB |
Output is correct |
47 |
Correct |
89 ms |
3028 KB |
Output is correct |
48 |
Correct |
101 ms |
3124 KB |
Output is correct |
49 |
Correct |
90 ms |
2996 KB |
Output is correct |
50 |
Correct |
346 ms |
3256 KB |
Output is correct |
51 |
Correct |
372 ms |
3424 KB |
Output is correct |
52 |
Correct |
343 ms |
3232 KB |
Output is correct |
53 |
Correct |
365 ms |
3412 KB |
Output is correct |
54 |
Correct |
335 ms |
3184 KB |
Output is correct |
55 |
Correct |
390 ms |
3520 KB |
Output is correct |
56 |
Correct |
337 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
66 ms |
2364 KB |
Output is correct |
10 |
Correct |
16 ms |
852 KB |
Output is correct |
11 |
Correct |
42 ms |
1620 KB |
Output is correct |
12 |
Correct |
42 ms |
1748 KB |
Output is correct |
13 |
Correct |
55 ms |
2072 KB |
Output is correct |
14 |
Correct |
41 ms |
1396 KB |
Output is correct |
15 |
Correct |
8 ms |
596 KB |
Output is correct |
16 |
Correct |
36 ms |
1492 KB |
Output is correct |
17 |
Correct |
90 ms |
3124 KB |
Output is correct |
18 |
Correct |
52 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
304 KB |
Output is correct |
34 |
Correct |
24 ms |
1204 KB |
Output is correct |
35 |
Correct |
67 ms |
2996 KB |
Output is correct |
36 |
Correct |
83 ms |
3440 KB |
Output is correct |
37 |
Correct |
117 ms |
3176 KB |
Output is correct |
38 |
Correct |
130 ms |
3492 KB |
Output is correct |
39 |
Correct |
65 ms |
2936 KB |
Output is correct |
40 |
Correct |
1 ms |
304 KB |
Output is correct |
41 |
Correct |
40 ms |
1728 KB |
Output is correct |
42 |
Correct |
75 ms |
3220 KB |
Output is correct |
43 |
Correct |
10 ms |
596 KB |
Output is correct |
44 |
Correct |
47 ms |
2132 KB |
Output is correct |
45 |
Correct |
60 ms |
2516 KB |
Output is correct |
46 |
Correct |
79 ms |
3388 KB |
Output is correct |
47 |
Correct |
27 ms |
1364 KB |
Output is correct |
48 |
Correct |
3 ms |
340 KB |
Output is correct |
49 |
Correct |
132 ms |
2976 KB |
Output is correct |
50 |
Correct |
103 ms |
3340 KB |
Output is correct |
51 |
Correct |
107 ms |
2900 KB |
Output is correct |
52 |
Correct |
98 ms |
3252 KB |
Output is correct |
53 |
Correct |
105 ms |
3412 KB |
Output is correct |
54 |
Correct |
147 ms |
3284 KB |
Output is correct |
55 |
Correct |
89 ms |
3028 KB |
Output is correct |
56 |
Correct |
101 ms |
3124 KB |
Output is correct |
57 |
Correct |
90 ms |
2996 KB |
Output is correct |
58 |
Correct |
346 ms |
3256 KB |
Output is correct |
59 |
Correct |
372 ms |
3424 KB |
Output is correct |
60 |
Correct |
343 ms |
3232 KB |
Output is correct |
61 |
Correct |
365 ms |
3412 KB |
Output is correct |
62 |
Correct |
335 ms |
3184 KB |
Output is correct |
63 |
Correct |
390 ms |
3520 KB |
Output is correct |
64 |
Correct |
337 ms |
3148 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
353 ms |
3324 KB |
Output is correct |
68 |
Correct |
356 ms |
3320 KB |
Output is correct |
69 |
Correct |
312 ms |
2924 KB |
Output is correct |
70 |
Correct |
351 ms |
3196 KB |
Output is correct |
71 |
Correct |
342 ms |
3260 KB |
Output is correct |
72 |
Correct |
338 ms |
3116 KB |
Output is correct |
73 |
Correct |
333 ms |
3056 KB |
Output is correct |
74 |
Correct |
372 ms |
3304 KB |
Output is correct |
75 |
Correct |
347 ms |
3156 KB |
Output is correct |
76 |
Correct |
356 ms |
3284 KB |
Output is correct |
77 |
Correct |
132 ms |
3476 KB |
Output is correct |
78 |
Correct |
93 ms |
3156 KB |
Output is correct |
79 |
Correct |
106 ms |
3048 KB |
Output is correct |
80 |
Correct |
109 ms |
3176 KB |
Output is correct |
81 |
Correct |
102 ms |
2952 KB |
Output is correct |
82 |
Correct |
109 ms |
3440 KB |
Output is correct |
83 |
Correct |
95 ms |
3080 KB |
Output is correct |
84 |
Correct |
253 ms |
3412 KB |
Output is correct |
85 |
Correct |
371 ms |
3512 KB |
Output is correct |
86 |
Correct |
1 ms |
212 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |
88 |
Correct |
383 ms |
3532 KB |
Output is correct |
89 |
Correct |
76 ms |
980 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |