#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
#define int ll
const int N = 1e5 + 5;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
int n, k;
ll ans = INF;
vector < int > v;
int get(int x1, int y1, int d) {
x1 /= d;
y1 /= d;
return ((x1 % 2) == (y1 % 2));
}
int x[N], y[N];
main() {
cin >> n >> k;
for (int i = 1; i <= k; ++i) {
int x2, y2;
cin >> x[i] >> y[i] >> x2 >> y2;
}
v.push_back(1);
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
v.push_back(i);
if (n / i != i) {
v.push_back(n / i);
}
}
}
for (int i : v) {
int m = n / i, cnt_black = 0, cnt_white = 0;
ll black = (((m * m) / 2) + (m * m) % 2) * (i * 1ll * i);
ll white = (n * 1ll * n) - black;
for (int j = 1; j <= k; ++j) {
cnt_black += get(x[j] - 1, y[j] - 1, i);
}
cnt_white = k - cnt_black;
ll x = (black - cnt_black) + cnt_white;
ll y = (white - cnt_white) + cnt_black;
ans = min(ans, min(x, y));
}
cout << ans;
}
Compilation message
chessboard.cpp:30:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
448 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
1548 KB |
Output is correct |
2 |
Correct |
23 ms |
1548 KB |
Output is correct |
3 |
Correct |
57 ms |
1548 KB |
Output is correct |
4 |
Correct |
57 ms |
1548 KB |
Output is correct |
5 |
Correct |
79 ms |
1548 KB |
Output is correct |
6 |
Correct |
50 ms |
1548 KB |
Output is correct |
7 |
Correct |
12 ms |
1548 KB |
Output is correct |
8 |
Correct |
51 ms |
1548 KB |
Output is correct |
9 |
Correct |
125 ms |
1888 KB |
Output is correct |
10 |
Correct |
73 ms |
1888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1888 KB |
Output is correct |
2 |
Correct |
2 ms |
1888 KB |
Output is correct |
3 |
Correct |
2 ms |
1888 KB |
Output is correct |
4 |
Correct |
3 ms |
1888 KB |
Output is correct |
5 |
Correct |
3 ms |
1888 KB |
Output is correct |
6 |
Correct |
2 ms |
1888 KB |
Output is correct |
7 |
Correct |
3 ms |
1888 KB |
Output is correct |
8 |
Correct |
3 ms |
1888 KB |
Output is correct |
9 |
Correct |
3 ms |
1888 KB |
Output is correct |
10 |
Correct |
2 ms |
1888 KB |
Output is correct |
11 |
Correct |
2 ms |
1888 KB |
Output is correct |
12 |
Correct |
2 ms |
1888 KB |
Output is correct |
13 |
Correct |
3 ms |
1888 KB |
Output is correct |
14 |
Correct |
3 ms |
1888 KB |
Output is correct |
15 |
Correct |
3 ms |
1888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1888 KB |
Output is correct |
2 |
Correct |
2 ms |
1888 KB |
Output is correct |
3 |
Correct |
2 ms |
1888 KB |
Output is correct |
4 |
Correct |
3 ms |
1888 KB |
Output is correct |
5 |
Correct |
3 ms |
1888 KB |
Output is correct |
6 |
Correct |
2 ms |
1888 KB |
Output is correct |
7 |
Correct |
3 ms |
1888 KB |
Output is correct |
8 |
Correct |
3 ms |
1888 KB |
Output is correct |
9 |
Correct |
3 ms |
1888 KB |
Output is correct |
10 |
Correct |
2 ms |
1888 KB |
Output is correct |
11 |
Correct |
2 ms |
1888 KB |
Output is correct |
12 |
Correct |
2 ms |
1888 KB |
Output is correct |
13 |
Correct |
3 ms |
1888 KB |
Output is correct |
14 |
Correct |
3 ms |
1888 KB |
Output is correct |
15 |
Correct |
3 ms |
1888 KB |
Output is correct |
16 |
Correct |
32 ms |
1888 KB |
Output is correct |
17 |
Correct |
90 ms |
1888 KB |
Output is correct |
18 |
Correct |
111 ms |
2200 KB |
Output is correct |
19 |
Correct |
152 ms |
2200 KB |
Output is correct |
20 |
Correct |
171 ms |
2200 KB |
Output is correct |
21 |
Correct |
86 ms |
2200 KB |
Output is correct |
22 |
Correct |
3 ms |
2200 KB |
Output is correct |
23 |
Correct |
53 ms |
2200 KB |
Output is correct |
24 |
Correct |
99 ms |
2200 KB |
Output is correct |
25 |
Correct |
12 ms |
2200 KB |
Output is correct |
26 |
Correct |
64 ms |
2200 KB |
Output is correct |
27 |
Correct |
82 ms |
2200 KB |
Output is correct |
28 |
Correct |
105 ms |
2200 KB |
Output is correct |
29 |
Correct |
37 ms |
2200 KB |
Output is correct |
30 |
Correct |
5 ms |
2200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
1548 KB |
Output is correct |
2 |
Correct |
23 ms |
1548 KB |
Output is correct |
3 |
Correct |
57 ms |
1548 KB |
Output is correct |
4 |
Correct |
57 ms |
1548 KB |
Output is correct |
5 |
Correct |
79 ms |
1548 KB |
Output is correct |
6 |
Correct |
50 ms |
1548 KB |
Output is correct |
7 |
Correct |
12 ms |
1548 KB |
Output is correct |
8 |
Correct |
51 ms |
1548 KB |
Output is correct |
9 |
Correct |
125 ms |
1888 KB |
Output is correct |
10 |
Correct |
73 ms |
1888 KB |
Output is correct |
11 |
Correct |
2 ms |
1888 KB |
Output is correct |
12 |
Correct |
2 ms |
1888 KB |
Output is correct |
13 |
Correct |
2 ms |
1888 KB |
Output is correct |
14 |
Correct |
3 ms |
1888 KB |
Output is correct |
15 |
Correct |
3 ms |
1888 KB |
Output is correct |
16 |
Correct |
2 ms |
1888 KB |
Output is correct |
17 |
Correct |
3 ms |
1888 KB |
Output is correct |
18 |
Correct |
3 ms |
1888 KB |
Output is correct |
19 |
Correct |
3 ms |
1888 KB |
Output is correct |
20 |
Correct |
2 ms |
1888 KB |
Output is correct |
21 |
Correct |
2 ms |
1888 KB |
Output is correct |
22 |
Correct |
2 ms |
1888 KB |
Output is correct |
23 |
Correct |
3 ms |
1888 KB |
Output is correct |
24 |
Correct |
3 ms |
1888 KB |
Output is correct |
25 |
Correct |
3 ms |
1888 KB |
Output is correct |
26 |
Correct |
32 ms |
1888 KB |
Output is correct |
27 |
Correct |
90 ms |
1888 KB |
Output is correct |
28 |
Correct |
111 ms |
2200 KB |
Output is correct |
29 |
Correct |
152 ms |
2200 KB |
Output is correct |
30 |
Correct |
171 ms |
2200 KB |
Output is correct |
31 |
Correct |
86 ms |
2200 KB |
Output is correct |
32 |
Correct |
3 ms |
2200 KB |
Output is correct |
33 |
Correct |
53 ms |
2200 KB |
Output is correct |
34 |
Correct |
99 ms |
2200 KB |
Output is correct |
35 |
Correct |
12 ms |
2200 KB |
Output is correct |
36 |
Correct |
64 ms |
2200 KB |
Output is correct |
37 |
Correct |
82 ms |
2200 KB |
Output is correct |
38 |
Correct |
105 ms |
2200 KB |
Output is correct |
39 |
Correct |
37 ms |
2200 KB |
Output is correct |
40 |
Correct |
5 ms |
2200 KB |
Output is correct |
41 |
Correct |
166 ms |
2200 KB |
Output is correct |
42 |
Correct |
141 ms |
2200 KB |
Output is correct |
43 |
Correct |
142 ms |
2200 KB |
Output is correct |
44 |
Correct |
138 ms |
2200 KB |
Output is correct |
45 |
Correct |
139 ms |
2200 KB |
Output is correct |
46 |
Correct |
185 ms |
2200 KB |
Output is correct |
47 |
Correct |
122 ms |
2200 KB |
Output is correct |
48 |
Correct |
141 ms |
2200 KB |
Output is correct |
49 |
Correct |
125 ms |
2200 KB |
Output is correct |
50 |
Correct |
429 ms |
2200 KB |
Output is correct |
51 |
Correct |
452 ms |
2264 KB |
Output is correct |
52 |
Correct |
419 ms |
2264 KB |
Output is correct |
53 |
Correct |
454 ms |
2284 KB |
Output is correct |
54 |
Correct |
413 ms |
2284 KB |
Output is correct |
55 |
Correct |
468 ms |
2284 KB |
Output is correct |
56 |
Correct |
401 ms |
2284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
448 KB |
Output is correct |
5 |
Correct |
2 ms |
448 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
464 KB |
Output is correct |
9 |
Correct |
89 ms |
1548 KB |
Output is correct |
10 |
Correct |
23 ms |
1548 KB |
Output is correct |
11 |
Correct |
57 ms |
1548 KB |
Output is correct |
12 |
Correct |
57 ms |
1548 KB |
Output is correct |
13 |
Correct |
79 ms |
1548 KB |
Output is correct |
14 |
Correct |
50 ms |
1548 KB |
Output is correct |
15 |
Correct |
12 ms |
1548 KB |
Output is correct |
16 |
Correct |
51 ms |
1548 KB |
Output is correct |
17 |
Correct |
125 ms |
1888 KB |
Output is correct |
18 |
Correct |
73 ms |
1888 KB |
Output is correct |
19 |
Correct |
2 ms |
1888 KB |
Output is correct |
20 |
Correct |
2 ms |
1888 KB |
Output is correct |
21 |
Correct |
2 ms |
1888 KB |
Output is correct |
22 |
Correct |
3 ms |
1888 KB |
Output is correct |
23 |
Correct |
3 ms |
1888 KB |
Output is correct |
24 |
Correct |
2 ms |
1888 KB |
Output is correct |
25 |
Correct |
3 ms |
1888 KB |
Output is correct |
26 |
Correct |
3 ms |
1888 KB |
Output is correct |
27 |
Correct |
3 ms |
1888 KB |
Output is correct |
28 |
Correct |
2 ms |
1888 KB |
Output is correct |
29 |
Correct |
2 ms |
1888 KB |
Output is correct |
30 |
Correct |
2 ms |
1888 KB |
Output is correct |
31 |
Correct |
3 ms |
1888 KB |
Output is correct |
32 |
Correct |
3 ms |
1888 KB |
Output is correct |
33 |
Correct |
3 ms |
1888 KB |
Output is correct |
34 |
Correct |
32 ms |
1888 KB |
Output is correct |
35 |
Correct |
90 ms |
1888 KB |
Output is correct |
36 |
Correct |
111 ms |
2200 KB |
Output is correct |
37 |
Correct |
152 ms |
2200 KB |
Output is correct |
38 |
Correct |
171 ms |
2200 KB |
Output is correct |
39 |
Correct |
86 ms |
2200 KB |
Output is correct |
40 |
Correct |
3 ms |
2200 KB |
Output is correct |
41 |
Correct |
53 ms |
2200 KB |
Output is correct |
42 |
Correct |
99 ms |
2200 KB |
Output is correct |
43 |
Correct |
12 ms |
2200 KB |
Output is correct |
44 |
Correct |
64 ms |
2200 KB |
Output is correct |
45 |
Correct |
82 ms |
2200 KB |
Output is correct |
46 |
Correct |
105 ms |
2200 KB |
Output is correct |
47 |
Correct |
37 ms |
2200 KB |
Output is correct |
48 |
Correct |
5 ms |
2200 KB |
Output is correct |
49 |
Correct |
166 ms |
2200 KB |
Output is correct |
50 |
Correct |
141 ms |
2200 KB |
Output is correct |
51 |
Correct |
142 ms |
2200 KB |
Output is correct |
52 |
Correct |
138 ms |
2200 KB |
Output is correct |
53 |
Correct |
139 ms |
2200 KB |
Output is correct |
54 |
Correct |
185 ms |
2200 KB |
Output is correct |
55 |
Correct |
122 ms |
2200 KB |
Output is correct |
56 |
Correct |
141 ms |
2200 KB |
Output is correct |
57 |
Correct |
125 ms |
2200 KB |
Output is correct |
58 |
Correct |
429 ms |
2200 KB |
Output is correct |
59 |
Correct |
452 ms |
2264 KB |
Output is correct |
60 |
Correct |
419 ms |
2264 KB |
Output is correct |
61 |
Correct |
454 ms |
2284 KB |
Output is correct |
62 |
Correct |
413 ms |
2284 KB |
Output is correct |
63 |
Correct |
468 ms |
2284 KB |
Output is correct |
64 |
Correct |
401 ms |
2284 KB |
Output is correct |
65 |
Correct |
2 ms |
2284 KB |
Output is correct |
66 |
Incorrect |
2 ms |
2284 KB |
Output isn't correct |
67 |
Halted |
0 ms |
0 KB |
- |