/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define all(data) data.begin(), data.end()
#define endl '\n'
#define ll long long
//#define int long long
#define pii pair < int, int >
using namespace std;
const int N = 2e5 + 5;
int n, k, x[N], y[N];
long long get(int dv) {
long long res1 = 0, res2 = 0, need = 0;
for(int i = 1; i <= k; i++) {
if(((x[i] + dv - 1) / dv + (y[i] + dv - 1) / dv) % 2 == 0) {
res1++;
} else {
res2++;
}
}
//cout << dv << " " << res1 + ((n / dv) * (n / dv)) / 2 * dv * dv - res2 << " " << res2 + ((n / dv) * (n / dv) + 1) / 2 * dv * dv - res1 << endl;
return min(res1 + ((n / dv) * (n / dv)) / 2 * dv * dv - res2, res2 + ((n / dv) * (n / dv) + 1) / 2 * dv * dv - res1);
}
main() {
//file("pieaters");
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= k; i++) {
int xx, yy;
cin >> x[i] >> y[i] >> xx >> yy;
}
long long ans = n * n;
for(int i = 1; i < n; i++) {
if(n % i == 0) {
ans = min(ans, get(i));
}
}
cout << ans;
}
Compilation message
chessboard.cpp: In function 'long long int get(int)':
chessboard.cpp:22:35: warning: unused variable 'need' [-Wunused-variable]
22 | long long res1 = 0, res2 = 0, need = 0;
| ^~~~
chessboard.cpp: At global scope:
chessboard.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
2204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
15 ms |
952 KB |
Output is correct |
17 |
Correct |
29 ms |
2320 KB |
Output is correct |
18 |
Correct |
35 ms |
2576 KB |
Output is correct |
19 |
Correct |
70 ms |
2424 KB |
Output is correct |
20 |
Correct |
76 ms |
2644 KB |
Output is correct |
21 |
Correct |
35 ms |
2224 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
17 ms |
1252 KB |
Output is correct |
24 |
Correct |
29 ms |
2404 KB |
Output is correct |
25 |
Correct |
4 ms |
472 KB |
Output is correct |
26 |
Correct |
18 ms |
1596 KB |
Output is correct |
27 |
Correct |
21 ms |
1872 KB |
Output is correct |
28 |
Correct |
36 ms |
2512 KB |
Output is correct |
29 |
Correct |
13 ms |
1092 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
2204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
22 ms |
2204 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |