#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#define x1 X
#define x2 XX
#define y1 Y
#define y2 YY
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long double ld;
#define f first
#define s second
using namespace std;
const int N = 2e5 + 123;
int n, k, x1[N], x2[N], y1[N], y2[N];
ll ans = 1e18;
int get(int x, int side) {
if (x < 0) return 0;
int id = x / side;
int ans = (id + 1) / 2 * side;
if (!(id & 1)) ans += x % side + 1;
return ans;
}
ll calc(int side) {
if (side == n) return 1e18;
ll even = 0, odd = 0;
for (int i = 0;i < k;i++) {
// number of even elements
ll a1 = get(y2[i], side) - get(y1[i] - 1, side);
ll a2 = y2[i] - y1[i] + 1 - a1;
ll b1 = get(x2[i], side) - get(x1[i] - 1, side);
ll b2 = x2[i] - x1[i] + 1 - b1;
int idx = x1[i] / side;
int idy = y1[i] / side;
// row is odd
if (idx & 1) {
swap(a1, a2);
}
// column is odd
if (idy & 1) {
swap(b1, b2);
}
// cout << "i = " << i << " a1 = " << a1 << " a2 = " << a2 << " b1 = " << b1 << " b2 = " << b2 << endl;
// cout << "x1 = " << x1[i] << " x2 = " << x2[i] << " y1 = " << y1[i] << " y2 = " << y2[i] << endl;
// cout << "Ylen = " << y2[i] - y1[i] + 1 << endl;
//
ll f0 = 1ll * a1 * b1 + 1ll * a2 * b2;
ll f1 = 1ll * a2 * b1 + 1ll * a1 * b2;
if (!((idx + idy) & 1)) swap(f0, f1);
odd += f1;
even += f0;
}
int cnt = n / side;
ll tot = 1ll * cnt * cnt;
// case 1 black - even, white - odd
ll E = (tot / 2) * 1ll * side * side - even + odd;
// case 2 black - odd, white - even
ll O = (tot + 1) / 2 * 1ll * side * side - odd + even;
return min(E, O);
}
int main() {
#ifdef wws
freopen("input", "r", stdin);
#endif
scanf("%d%d", &n, &k);
for (int i = 0;i < k;i++) {
scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
x1[i]--;
x2[i]--;
y1[i]--;
y2[i]--;
}
//cout << calc(1) << endl; return 0;
for (int i = 1;1ll * i * i <= n;i++) {
if (n % i == 0) {
ans = min(ans, calc(i));
if (n / i != i) ans = min(ans, calc(n / i));
}
}
cout << ans << endl;
return 0;
}
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
560 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
3 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2756 KB |
Output is correct |
2 |
Correct |
18 ms |
2756 KB |
Output is correct |
3 |
Correct |
31 ms |
2756 KB |
Output is correct |
4 |
Correct |
29 ms |
2756 KB |
Output is correct |
5 |
Correct |
35 ms |
2756 KB |
Output is correct |
6 |
Correct |
35 ms |
2756 KB |
Output is correct |
7 |
Correct |
9 ms |
2756 KB |
Output is correct |
8 |
Correct |
25 ms |
2756 KB |
Output is correct |
9 |
Correct |
53 ms |
3164 KB |
Output is correct |
10 |
Correct |
31 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3164 KB |
Output is correct |
2 |
Correct |
3 ms |
3164 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
5 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
3 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
3 ms |
3164 KB |
Output is correct |
12 |
Correct |
3 ms |
3164 KB |
Output is correct |
13 |
Correct |
3 ms |
3164 KB |
Output is correct |
14 |
Correct |
3 ms |
3164 KB |
Output is correct |
15 |
Correct |
3 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3164 KB |
Output is correct |
2 |
Correct |
3 ms |
3164 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
5 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
3 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
3 ms |
3164 KB |
Output is correct |
12 |
Correct |
3 ms |
3164 KB |
Output is correct |
13 |
Correct |
3 ms |
3164 KB |
Output is correct |
14 |
Correct |
3 ms |
3164 KB |
Output is correct |
15 |
Correct |
3 ms |
3164 KB |
Output is correct |
16 |
Correct |
22 ms |
3164 KB |
Output is correct |
17 |
Correct |
51 ms |
3164 KB |
Output is correct |
18 |
Correct |
77 ms |
3216 KB |
Output is correct |
19 |
Correct |
188 ms |
3216 KB |
Output is correct |
20 |
Correct |
255 ms |
3304 KB |
Output is correct |
21 |
Correct |
44 ms |
3304 KB |
Output is correct |
22 |
Correct |
3 ms |
3304 KB |
Output is correct |
23 |
Correct |
43 ms |
3304 KB |
Output is correct |
24 |
Correct |
64 ms |
3304 KB |
Output is correct |
25 |
Correct |
8 ms |
3304 KB |
Output is correct |
26 |
Correct |
38 ms |
3304 KB |
Output is correct |
27 |
Correct |
56 ms |
3304 KB |
Output is correct |
28 |
Correct |
82 ms |
3304 KB |
Output is correct |
29 |
Correct |
19 ms |
3304 KB |
Output is correct |
30 |
Correct |
4 ms |
3304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2756 KB |
Output is correct |
2 |
Correct |
18 ms |
2756 KB |
Output is correct |
3 |
Correct |
31 ms |
2756 KB |
Output is correct |
4 |
Correct |
29 ms |
2756 KB |
Output is correct |
5 |
Correct |
35 ms |
2756 KB |
Output is correct |
6 |
Correct |
35 ms |
2756 KB |
Output is correct |
7 |
Correct |
9 ms |
2756 KB |
Output is correct |
8 |
Correct |
25 ms |
2756 KB |
Output is correct |
9 |
Correct |
53 ms |
3164 KB |
Output is correct |
10 |
Correct |
31 ms |
3164 KB |
Output is correct |
11 |
Correct |
3 ms |
3164 KB |
Output is correct |
12 |
Correct |
3 ms |
3164 KB |
Output is correct |
13 |
Correct |
3 ms |
3164 KB |
Output is correct |
14 |
Correct |
3 ms |
3164 KB |
Output is correct |
15 |
Correct |
5 ms |
3164 KB |
Output is correct |
16 |
Correct |
2 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
3 ms |
3164 KB |
Output is correct |
19 |
Correct |
2 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3164 KB |
Output is correct |
21 |
Correct |
3 ms |
3164 KB |
Output is correct |
22 |
Correct |
3 ms |
3164 KB |
Output is correct |
23 |
Correct |
3 ms |
3164 KB |
Output is correct |
24 |
Correct |
3 ms |
3164 KB |
Output is correct |
25 |
Correct |
3 ms |
3164 KB |
Output is correct |
26 |
Correct |
22 ms |
3164 KB |
Output is correct |
27 |
Correct |
51 ms |
3164 KB |
Output is correct |
28 |
Correct |
77 ms |
3216 KB |
Output is correct |
29 |
Correct |
188 ms |
3216 KB |
Output is correct |
30 |
Correct |
255 ms |
3304 KB |
Output is correct |
31 |
Correct |
44 ms |
3304 KB |
Output is correct |
32 |
Correct |
3 ms |
3304 KB |
Output is correct |
33 |
Correct |
43 ms |
3304 KB |
Output is correct |
34 |
Correct |
64 ms |
3304 KB |
Output is correct |
35 |
Correct |
8 ms |
3304 KB |
Output is correct |
36 |
Correct |
38 ms |
3304 KB |
Output is correct |
37 |
Correct |
56 ms |
3304 KB |
Output is correct |
38 |
Correct |
82 ms |
3304 KB |
Output is correct |
39 |
Correct |
19 ms |
3304 KB |
Output is correct |
40 |
Correct |
4 ms |
3304 KB |
Output is correct |
41 |
Correct |
169 ms |
3304 KB |
Output is correct |
42 |
Correct |
72 ms |
3304 KB |
Output is correct |
43 |
Correct |
106 ms |
3304 KB |
Output is correct |
44 |
Correct |
75 ms |
3304 KB |
Output is correct |
45 |
Correct |
68 ms |
3320 KB |
Output is correct |
46 |
Correct |
175 ms |
3320 KB |
Output is correct |
47 |
Correct |
55 ms |
3320 KB |
Output is correct |
48 |
Correct |
89 ms |
3320 KB |
Output is correct |
49 |
Correct |
79 ms |
3320 KB |
Output is correct |
50 |
Correct |
744 ms |
3320 KB |
Output is correct |
51 |
Correct |
803 ms |
3388 KB |
Output is correct |
52 |
Correct |
741 ms |
3388 KB |
Output is correct |
53 |
Correct |
723 ms |
3388 KB |
Output is correct |
54 |
Correct |
791 ms |
3388 KB |
Output is correct |
55 |
Correct |
880 ms |
3420 KB |
Output is correct |
56 |
Correct |
682 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
560 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
3 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
560 KB |
Output is correct |
9 |
Correct |
47 ms |
2756 KB |
Output is correct |
10 |
Correct |
18 ms |
2756 KB |
Output is correct |
11 |
Correct |
31 ms |
2756 KB |
Output is correct |
12 |
Correct |
29 ms |
2756 KB |
Output is correct |
13 |
Correct |
35 ms |
2756 KB |
Output is correct |
14 |
Correct |
35 ms |
2756 KB |
Output is correct |
15 |
Correct |
9 ms |
2756 KB |
Output is correct |
16 |
Correct |
25 ms |
2756 KB |
Output is correct |
17 |
Correct |
53 ms |
3164 KB |
Output is correct |
18 |
Correct |
31 ms |
3164 KB |
Output is correct |
19 |
Correct |
3 ms |
3164 KB |
Output is correct |
20 |
Correct |
3 ms |
3164 KB |
Output is correct |
21 |
Correct |
3 ms |
3164 KB |
Output is correct |
22 |
Correct |
3 ms |
3164 KB |
Output is correct |
23 |
Correct |
5 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3164 KB |
Output is correct |
26 |
Correct |
3 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3164 KB |
Output is correct |
29 |
Correct |
3 ms |
3164 KB |
Output is correct |
30 |
Correct |
3 ms |
3164 KB |
Output is correct |
31 |
Correct |
3 ms |
3164 KB |
Output is correct |
32 |
Correct |
3 ms |
3164 KB |
Output is correct |
33 |
Correct |
3 ms |
3164 KB |
Output is correct |
34 |
Correct |
22 ms |
3164 KB |
Output is correct |
35 |
Correct |
51 ms |
3164 KB |
Output is correct |
36 |
Correct |
77 ms |
3216 KB |
Output is correct |
37 |
Correct |
188 ms |
3216 KB |
Output is correct |
38 |
Correct |
255 ms |
3304 KB |
Output is correct |
39 |
Correct |
44 ms |
3304 KB |
Output is correct |
40 |
Correct |
3 ms |
3304 KB |
Output is correct |
41 |
Correct |
43 ms |
3304 KB |
Output is correct |
42 |
Correct |
64 ms |
3304 KB |
Output is correct |
43 |
Correct |
8 ms |
3304 KB |
Output is correct |
44 |
Correct |
38 ms |
3304 KB |
Output is correct |
45 |
Correct |
56 ms |
3304 KB |
Output is correct |
46 |
Correct |
82 ms |
3304 KB |
Output is correct |
47 |
Correct |
19 ms |
3304 KB |
Output is correct |
48 |
Correct |
4 ms |
3304 KB |
Output is correct |
49 |
Correct |
169 ms |
3304 KB |
Output is correct |
50 |
Correct |
72 ms |
3304 KB |
Output is correct |
51 |
Correct |
106 ms |
3304 KB |
Output is correct |
52 |
Correct |
75 ms |
3304 KB |
Output is correct |
53 |
Correct |
68 ms |
3320 KB |
Output is correct |
54 |
Correct |
175 ms |
3320 KB |
Output is correct |
55 |
Correct |
55 ms |
3320 KB |
Output is correct |
56 |
Correct |
89 ms |
3320 KB |
Output is correct |
57 |
Correct |
79 ms |
3320 KB |
Output is correct |
58 |
Correct |
744 ms |
3320 KB |
Output is correct |
59 |
Correct |
803 ms |
3388 KB |
Output is correct |
60 |
Correct |
741 ms |
3388 KB |
Output is correct |
61 |
Correct |
723 ms |
3388 KB |
Output is correct |
62 |
Correct |
791 ms |
3388 KB |
Output is correct |
63 |
Correct |
880 ms |
3420 KB |
Output is correct |
64 |
Correct |
682 ms |
3420 KB |
Output is correct |
65 |
Correct |
3 ms |
3420 KB |
Output is correct |
66 |
Correct |
2 ms |
3420 KB |
Output is correct |
67 |
Correct |
737 ms |
3420 KB |
Output is correct |
68 |
Correct |
695 ms |
5432 KB |
Output is correct |
69 |
Correct |
582 ms |
7224 KB |
Output is correct |
70 |
Correct |
629 ms |
9512 KB |
Output is correct |
71 |
Correct |
670 ms |
11736 KB |
Output is correct |
72 |
Correct |
679 ms |
13700 KB |
Output is correct |
73 |
Correct |
659 ms |
15680 KB |
Output is correct |
74 |
Correct |
823 ms |
17964 KB |
Output is correct |
75 |
Correct |
625 ms |
20152 KB |
Output is correct |
76 |
Correct |
706 ms |
22532 KB |
Output is correct |
77 |
Correct |
171 ms |
24916 KB |
Output is correct |
78 |
Correct |
82 ms |
26908 KB |
Output is correct |
79 |
Correct |
146 ms |
28720 KB |
Output is correct |
80 |
Correct |
105 ms |
30928 KB |
Output is correct |
81 |
Correct |
101 ms |
32760 KB |
Output is correct |
82 |
Correct |
146 ms |
35188 KB |
Output is correct |
83 |
Correct |
87 ms |
37192 KB |
Output is correct |
84 |
Correct |
449 ms |
39708 KB |
Output is correct |
85 |
Correct |
714 ms |
42092 KB |
Output is correct |
86 |
Correct |
3 ms |
42092 KB |
Output is correct |
87 |
Correct |
2 ms |
42092 KB |
Output is correct |
88 |
Correct |
779 ms |
44520 KB |
Output is correct |
89 |
Correct |
147 ms |
44520 KB |
Output is correct |
90 |
Correct |
2 ms |
44520 KB |
Output is correct |