#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
#define int long long
using namespace std;
const int N = (1e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
int ans = 1e18;
int n, k, x[2][N], y[2][N];
void calc(int div){
int bl = n / div, cnt = 0, x1, y1, cnt1 = 0;
if(bl & 1){
cnt += div * div * ((bl + 1) / 2) * ((bl + 1) / 2);
cnt += div * div * (bl / 2) * (bl / 2);
cnt1 = n * n - cnt;
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
x1 = (x1 + div - 1) / div;
y1 = (y1 + div - 1) / div;
//cout << x1 << " " << y1 << endl;
if((x1 + y1) % 2 == 0){
cnt--;
cnt1++;
}
else{
cnt++;
cnt1--;
}
}
ans = min(ans, cnt);
ans = min(ans, cnt1);
}
else{
cnt += div * div * (bl / 2) * bl;
cnt1 = n * n - cnt;
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
x1 = (x1 + div - 1) / div;
y1 = (y1 + div - 1) / div;
if((x1 + y1) % 2 == 0){
cnt--;
cnt1++;
}
else{
cnt++;
cnt1--;
}
}
ans = min(ans, cnt);
ans = min(ans, cnt1);
}
}
main()
{
cin >> n >> k;
for(int i = 1;i <= k; i++){
scanf("%lld%lld%lld%lld", &x[0][i], &y[0][i], &x[1][i], &y[1][i]);
}
if(n % 2 == 1){
int x1, y1;
int cnt = n * n / 2ll + 1ll, cnt1 = n * n / 2ll;
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
if((x1 + y1) % 2 == 0){
cnt--;
cnt1++;
}
else{
cnt++;
cnt1--;
}
}
ans = min(ans, cnt);
ans = min(ans, cnt1);
}
else{
int x1, y1;
int cnt = n * n / 2ll, cnt1 = n * n / 2ll;
for(int i = 1;i <= k; i++){
x1 = x[0][i];
y1 = y[0][i];
if((x1 + y1) % 2 == 0){
cnt--;
cnt1++;
}
else{
cnt++;
cnt1--;
}
}
ans = min(ans, cnt);
ans = min(ans, cnt1);
}
for(int i = 2;i * i <= n; i++){
if(n % i == 0){
calc(i);
calc(n / i);
}
}
cout << ans;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
Compilation message
chessboard.cpp:64:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
chessboard.cpp: In function 'int main()':
chessboard.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld%lld", &x[0][i], &y[0][i], &x[1][i], &y[1][i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
128 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2296 KB |
Output is correct |
2 |
Correct |
10 ms |
888 KB |
Output is correct |
3 |
Correct |
22 ms |
1528 KB |
Output is correct |
4 |
Correct |
22 ms |
1784 KB |
Output is correct |
5 |
Correct |
28 ms |
2040 KB |
Output is correct |
6 |
Correct |
19 ms |
1528 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
19 ms |
1528 KB |
Output is correct |
9 |
Correct |
46 ms |
3112 KB |
Output is correct |
10 |
Correct |
30 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
368 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
368 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
15 ms |
1596 KB |
Output is correct |
17 |
Correct |
37 ms |
4348 KB |
Output is correct |
18 |
Correct |
50 ms |
4984 KB |
Output is correct |
19 |
Correct |
122 ms |
4472 KB |
Output is correct |
20 |
Correct |
134 ms |
4984 KB |
Output is correct |
21 |
Correct |
36 ms |
4212 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
29 ms |
2424 KB |
Output is correct |
24 |
Correct |
48 ms |
4600 KB |
Output is correct |
25 |
Correct |
7 ms |
764 KB |
Output is correct |
26 |
Correct |
30 ms |
3064 KB |
Output is correct |
27 |
Correct |
40 ms |
3576 KB |
Output is correct |
28 |
Correct |
50 ms |
4856 KB |
Output is correct |
29 |
Correct |
16 ms |
1928 KB |
Output is correct |
30 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2296 KB |
Output is correct |
2 |
Correct |
10 ms |
888 KB |
Output is correct |
3 |
Correct |
22 ms |
1528 KB |
Output is correct |
4 |
Correct |
22 ms |
1784 KB |
Output is correct |
5 |
Correct |
28 ms |
2040 KB |
Output is correct |
6 |
Correct |
19 ms |
1528 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
19 ms |
1528 KB |
Output is correct |
9 |
Correct |
46 ms |
3112 KB |
Output is correct |
10 |
Correct |
30 ms |
1912 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
368 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
15 ms |
1596 KB |
Output is correct |
27 |
Correct |
37 ms |
4348 KB |
Output is correct |
28 |
Correct |
50 ms |
4984 KB |
Output is correct |
29 |
Correct |
122 ms |
4472 KB |
Output is correct |
30 |
Correct |
134 ms |
4984 KB |
Output is correct |
31 |
Correct |
36 ms |
4212 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
29 ms |
2424 KB |
Output is correct |
34 |
Correct |
48 ms |
4600 KB |
Output is correct |
35 |
Correct |
7 ms |
764 KB |
Output is correct |
36 |
Correct |
30 ms |
3064 KB |
Output is correct |
37 |
Correct |
40 ms |
3576 KB |
Output is correct |
38 |
Correct |
50 ms |
4856 KB |
Output is correct |
39 |
Correct |
16 ms |
1928 KB |
Output is correct |
40 |
Correct |
4 ms |
504 KB |
Output is correct |
41 |
Correct |
107 ms |
4988 KB |
Output is correct |
42 |
Correct |
55 ms |
5596 KB |
Output is correct |
43 |
Correct |
73 ms |
4992 KB |
Output is correct |
44 |
Correct |
54 ms |
5368 KB |
Output is correct |
45 |
Correct |
51 ms |
5752 KB |
Output is correct |
46 |
Correct |
120 ms |
5496 KB |
Output is correct |
47 |
Correct |
45 ms |
5112 KB |
Output is correct |
48 |
Correct |
64 ms |
5124 KB |
Output is correct |
49 |
Correct |
50 ms |
4984 KB |
Output is correct |
50 |
Correct |
445 ms |
5404 KB |
Output is correct |
51 |
Correct |
475 ms |
5744 KB |
Output is correct |
52 |
Correct |
442 ms |
5244 KB |
Output is correct |
53 |
Correct |
473 ms |
5752 KB |
Output is correct |
54 |
Correct |
439 ms |
5368 KB |
Output is correct |
55 |
Correct |
493 ms |
5908 KB |
Output is correct |
56 |
Correct |
423 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
128 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
32 ms |
2296 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
22 ms |
1528 KB |
Output is correct |
12 |
Correct |
22 ms |
1784 KB |
Output is correct |
13 |
Correct |
28 ms |
2040 KB |
Output is correct |
14 |
Correct |
19 ms |
1528 KB |
Output is correct |
15 |
Correct |
6 ms |
632 KB |
Output is correct |
16 |
Correct |
19 ms |
1528 KB |
Output is correct |
17 |
Correct |
46 ms |
3112 KB |
Output is correct |
18 |
Correct |
30 ms |
1912 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
368 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
15 ms |
1596 KB |
Output is correct |
35 |
Correct |
37 ms |
4348 KB |
Output is correct |
36 |
Correct |
50 ms |
4984 KB |
Output is correct |
37 |
Correct |
122 ms |
4472 KB |
Output is correct |
38 |
Correct |
134 ms |
4984 KB |
Output is correct |
39 |
Correct |
36 ms |
4212 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
29 ms |
2424 KB |
Output is correct |
42 |
Correct |
48 ms |
4600 KB |
Output is correct |
43 |
Correct |
7 ms |
764 KB |
Output is correct |
44 |
Correct |
30 ms |
3064 KB |
Output is correct |
45 |
Correct |
40 ms |
3576 KB |
Output is correct |
46 |
Correct |
50 ms |
4856 KB |
Output is correct |
47 |
Correct |
16 ms |
1928 KB |
Output is correct |
48 |
Correct |
4 ms |
504 KB |
Output is correct |
49 |
Correct |
107 ms |
4988 KB |
Output is correct |
50 |
Correct |
55 ms |
5596 KB |
Output is correct |
51 |
Correct |
73 ms |
4992 KB |
Output is correct |
52 |
Correct |
54 ms |
5368 KB |
Output is correct |
53 |
Correct |
51 ms |
5752 KB |
Output is correct |
54 |
Correct |
120 ms |
5496 KB |
Output is correct |
55 |
Correct |
45 ms |
5112 KB |
Output is correct |
56 |
Correct |
64 ms |
5124 KB |
Output is correct |
57 |
Correct |
50 ms |
4984 KB |
Output is correct |
58 |
Correct |
445 ms |
5404 KB |
Output is correct |
59 |
Correct |
475 ms |
5744 KB |
Output is correct |
60 |
Correct |
442 ms |
5244 KB |
Output is correct |
61 |
Correct |
473 ms |
5752 KB |
Output is correct |
62 |
Correct |
439 ms |
5368 KB |
Output is correct |
63 |
Correct |
493 ms |
5908 KB |
Output is correct |
64 |
Correct |
423 ms |
5112 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |