#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)) {
auto c = [&](int v) {
return 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
3628 KB |
Output is correct |
2 |
Correct |
22 ms |
1172 KB |
Output is correct |
3 |
Correct |
44 ms |
2388 KB |
Output is correct |
4 |
Correct |
45 ms |
2504 KB |
Output is correct |
5 |
Correct |
57 ms |
3260 KB |
Output is correct |
6 |
Correct |
46 ms |
2200 KB |
Output is correct |
7 |
Correct |
11 ms |
576 KB |
Output is correct |
8 |
Correct |
41 ms |
2188 KB |
Output is correct |
9 |
Correct |
99 ms |
5128 KB |
Output is correct |
10 |
Correct |
53 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
24 ms |
1492 KB |
Output is correct |
17 |
Correct |
73 ms |
4176 KB |
Output is correct |
18 |
Correct |
87 ms |
4892 KB |
Output is correct |
19 |
Correct |
122 ms |
4468 KB |
Output is correct |
20 |
Correct |
143 ms |
4964 KB |
Output is correct |
21 |
Correct |
65 ms |
4084 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
48 ms |
2248 KB |
Output is correct |
24 |
Correct |
82 ms |
4556 KB |
Output is correct |
25 |
Correct |
10 ms |
676 KB |
Output is correct |
26 |
Correct |
52 ms |
2928 KB |
Output is correct |
27 |
Correct |
66 ms |
3412 KB |
Output is correct |
28 |
Correct |
81 ms |
4796 KB |
Output is correct |
29 |
Correct |
28 ms |
1824 KB |
Output is correct |
30 |
Correct |
3 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
3628 KB |
Output is correct |
2 |
Correct |
22 ms |
1172 KB |
Output is correct |
3 |
Correct |
44 ms |
2388 KB |
Output is correct |
4 |
Correct |
45 ms |
2504 KB |
Output is correct |
5 |
Correct |
57 ms |
3260 KB |
Output is correct |
6 |
Correct |
46 ms |
2200 KB |
Output is correct |
7 |
Correct |
11 ms |
576 KB |
Output is correct |
8 |
Correct |
41 ms |
2188 KB |
Output is correct |
9 |
Correct |
99 ms |
5128 KB |
Output is correct |
10 |
Correct |
53 ms |
3020 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
316 KB |
Output is correct |
26 |
Correct |
24 ms |
1492 KB |
Output is correct |
27 |
Correct |
73 ms |
4176 KB |
Output is correct |
28 |
Correct |
87 ms |
4892 KB |
Output is correct |
29 |
Correct |
122 ms |
4468 KB |
Output is correct |
30 |
Correct |
143 ms |
4964 KB |
Output is correct |
31 |
Correct |
65 ms |
4084 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
48 ms |
2248 KB |
Output is correct |
34 |
Correct |
82 ms |
4556 KB |
Output is correct |
35 |
Correct |
10 ms |
676 KB |
Output is correct |
36 |
Correct |
52 ms |
2928 KB |
Output is correct |
37 |
Correct |
66 ms |
3412 KB |
Output is correct |
38 |
Correct |
81 ms |
4796 KB |
Output is correct |
39 |
Correct |
28 ms |
1824 KB |
Output is correct |
40 |
Correct |
3 ms |
316 KB |
Output is correct |
41 |
Correct |
139 ms |
4812 KB |
Output is correct |
42 |
Correct |
107 ms |
5452 KB |
Output is correct |
43 |
Correct |
123 ms |
5000 KB |
Output is correct |
44 |
Correct |
113 ms |
5280 KB |
Output is correct |
45 |
Correct |
104 ms |
5752 KB |
Output is correct |
46 |
Correct |
151 ms |
5476 KB |
Output is correct |
47 |
Correct |
94 ms |
4996 KB |
Output is correct |
48 |
Correct |
111 ms |
5028 KB |
Output is correct |
49 |
Correct |
100 ms |
4800 KB |
Output is correct |
50 |
Correct |
359 ms |
5288 KB |
Output is correct |
51 |
Correct |
387 ms |
5632 KB |
Output is correct |
52 |
Correct |
352 ms |
5252 KB |
Output is correct |
53 |
Correct |
405 ms |
5580 KB |
Output is correct |
54 |
Correct |
355 ms |
5184 KB |
Output is correct |
55 |
Correct |
419 ms |
5788 KB |
Output is correct |
56 |
Correct |
355 ms |
5040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
70 ms |
3628 KB |
Output is correct |
10 |
Correct |
22 ms |
1172 KB |
Output is correct |
11 |
Correct |
44 ms |
2388 KB |
Output is correct |
12 |
Correct |
45 ms |
2504 KB |
Output is correct |
13 |
Correct |
57 ms |
3260 KB |
Output is correct |
14 |
Correct |
46 ms |
2200 KB |
Output is correct |
15 |
Correct |
11 ms |
576 KB |
Output is correct |
16 |
Correct |
41 ms |
2188 KB |
Output is correct |
17 |
Correct |
99 ms |
5128 KB |
Output is correct |
18 |
Correct |
53 ms |
3020 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 |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
1 ms |
308 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
24 ms |
1492 KB |
Output is correct |
35 |
Correct |
73 ms |
4176 KB |
Output is correct |
36 |
Correct |
87 ms |
4892 KB |
Output is correct |
37 |
Correct |
122 ms |
4468 KB |
Output is correct |
38 |
Correct |
143 ms |
4964 KB |
Output is correct |
39 |
Correct |
65 ms |
4084 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
48 ms |
2248 KB |
Output is correct |
42 |
Correct |
82 ms |
4556 KB |
Output is correct |
43 |
Correct |
10 ms |
676 KB |
Output is correct |
44 |
Correct |
52 ms |
2928 KB |
Output is correct |
45 |
Correct |
66 ms |
3412 KB |
Output is correct |
46 |
Correct |
81 ms |
4796 KB |
Output is correct |
47 |
Correct |
28 ms |
1824 KB |
Output is correct |
48 |
Correct |
3 ms |
316 KB |
Output is correct |
49 |
Correct |
139 ms |
4812 KB |
Output is correct |
50 |
Correct |
107 ms |
5452 KB |
Output is correct |
51 |
Correct |
123 ms |
5000 KB |
Output is correct |
52 |
Correct |
113 ms |
5280 KB |
Output is correct |
53 |
Correct |
104 ms |
5752 KB |
Output is correct |
54 |
Correct |
151 ms |
5476 KB |
Output is correct |
55 |
Correct |
94 ms |
4996 KB |
Output is correct |
56 |
Correct |
111 ms |
5028 KB |
Output is correct |
57 |
Correct |
100 ms |
4800 KB |
Output is correct |
58 |
Correct |
359 ms |
5288 KB |
Output is correct |
59 |
Correct |
387 ms |
5632 KB |
Output is correct |
60 |
Correct |
352 ms |
5252 KB |
Output is correct |
61 |
Correct |
405 ms |
5580 KB |
Output is correct |
62 |
Correct |
355 ms |
5184 KB |
Output is correct |
63 |
Correct |
419 ms |
5788 KB |
Output is correct |
64 |
Correct |
355 ms |
5040 KB |
Output is correct |
65 |
Correct |
0 ms |
300 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Correct |
378 ms |
5440 KB |
Output is correct |
68 |
Correct |
385 ms |
5492 KB |
Output is correct |
69 |
Correct |
321 ms |
4892 KB |
Output is correct |
70 |
Correct |
386 ms |
5248 KB |
Output is correct |
71 |
Correct |
376 ms |
5184 KB |
Output is correct |
72 |
Correct |
345 ms |
5016 KB |
Output is correct |
73 |
Correct |
351 ms |
4976 KB |
Output is correct |
74 |
Correct |
356 ms |
5460 KB |
Output is correct |
75 |
Correct |
369 ms |
5172 KB |
Output is correct |
76 |
Correct |
380 ms |
5380 KB |
Output is correct |
77 |
Correct |
139 ms |
5644 KB |
Output is correct |
78 |
Correct |
115 ms |
5164 KB |
Output is correct |
79 |
Correct |
114 ms |
4940 KB |
Output is correct |
80 |
Correct |
125 ms |
5092 KB |
Output is correct |
81 |
Correct |
127 ms |
4792 KB |
Output is correct |
82 |
Correct |
117 ms |
5452 KB |
Output is correct |
83 |
Correct |
106 ms |
5120 KB |
Output is correct |
84 |
Correct |
265 ms |
5580 KB |
Output is correct |
85 |
Correct |
402 ms |
5692 KB |
Output is correct |
86 |
Correct |
2 ms |
212 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |
88 |
Correct |
387 ms |
5780 KB |
Output is correct |
89 |
Correct |
82 ms |
1316 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |