//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 1005;
bool a[N][N]; // false -> white true -> black
int pref[2][N][N]; // 0 spitakneri qanaky minchev i,j u 1 severi qanaky
bool isprime(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
void KarginSolve() {
long long n, k;
cin >> n >> k;
long long sq = sqrt(n);
vector<int> div{1};
for (int i = 2;i <= sq;i++) {
if (n % i == 0) {
div.pb(i);
if (i * i != n) div.pb(n / i);
}
}
if (n <= 1000) {
for (int i = 0; i < k;i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
a[x1][y1] = true;
}
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= n;j++) {
for (int c = 0;c < 2;c++) {
pref[c][i][j] = pref[c][i - 1][j] + pref[c][i][j - 1] - pref[c][i - 1][j - 1] + (a[i][j] == c);
}
}
}
int ans = n * n / 2;
for (int d : div) {
if (d == n) continue;
int fw = 0, fb = 0;
for (int i = d, it = 1;i <= n;i += d, it++) {
for (int j = d, jt = 1;j <= n;j += d, jt++) {
if (it & 1) {
if (jt & 1) {
fb += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
fw += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
}
else {
fb += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
fw += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
}
}
else {
if (jt & 1) {
fb += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
fw += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
}
else {
fb += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
fw += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
}
}
}
}
ans = min(ans, min(fw, fb));
}
cout << ans << '\n';
}
else if (div.size() == 1) {
ll fw = n * n / 2, fb = (n * n + 1) / 2;
for (int i = 0;i < k;i++) {
int x, y, x1, y1;
cin >> x >> y >> x1 >> y1;
if (x & 1) {
if (y & 1) fb--, fw++;
else fw--, fb++;
}
else {
if (y & 1) fw--, fb++;
else fb--, fw++;
}
}
cout << min(fw, fb) << '\n';
}
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
chessboard.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
chessboard.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
chessboard.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
chessboard.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
612 KB |
Output is correct |
2 |
Correct |
5 ms |
604 KB |
Output is correct |
3 |
Correct |
11 ms |
1220 KB |
Output is correct |
4 |
Correct |
10 ms |
1248 KB |
Output is correct |
5 |
Correct |
13 ms |
1624 KB |
Output is correct |
6 |
Correct |
9 ms |
1116 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
10 ms |
1104 KB |
Output is correct |
9 |
Correct |
24 ms |
2388 KB |
Output is correct |
10 |
Correct |
13 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2904 KB |
Output is correct |
7 |
Correct |
2 ms |
3160 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2904 KB |
Output is correct |
14 |
Correct |
1 ms |
2908 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2904 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2904 KB |
Output is correct |
7 |
Correct |
2 ms |
3160 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2904 KB |
Output is correct |
14 |
Correct |
1 ms |
2908 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
14 ms |
9052 KB |
Output is correct |
17 |
Correct |
27 ms |
9308 KB |
Output is correct |
18 |
Correct |
29 ms |
9040 KB |
Output is correct |
19 |
Correct |
42 ms |
9096 KB |
Output is correct |
20 |
Correct |
31 ms |
9116 KB |
Output is correct |
21 |
Correct |
26 ms |
9308 KB |
Output is correct |
22 |
Correct |
8 ms |
9048 KB |
Output is correct |
23 |
Correct |
19 ms |
9168 KB |
Output is correct |
24 |
Correct |
24 ms |
9160 KB |
Output is correct |
25 |
Correct |
9 ms |
9052 KB |
Output is correct |
26 |
Correct |
19 ms |
9120 KB |
Output is correct |
27 |
Correct |
23 ms |
9128 KB |
Output is correct |
28 |
Correct |
25 ms |
9040 KB |
Output is correct |
29 |
Correct |
13 ms |
9052 KB |
Output is correct |
30 |
Correct |
10 ms |
9052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
612 KB |
Output is correct |
2 |
Correct |
5 ms |
604 KB |
Output is correct |
3 |
Correct |
11 ms |
1220 KB |
Output is correct |
4 |
Correct |
10 ms |
1248 KB |
Output is correct |
5 |
Correct |
13 ms |
1624 KB |
Output is correct |
6 |
Correct |
9 ms |
1116 KB |
Output is correct |
7 |
Correct |
3 ms |
632 KB |
Output is correct |
8 |
Correct |
10 ms |
1104 KB |
Output is correct |
9 |
Correct |
24 ms |
2388 KB |
Output is correct |
10 |
Correct |
13 ms |
1624 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
2908 KB |
Output is correct |
13 |
Correct |
2 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2904 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
2904 KB |
Output is correct |
17 |
Correct |
2 ms |
3160 KB |
Output is correct |
18 |
Correct |
1 ms |
2908 KB |
Output is correct |
19 |
Correct |
2 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
2908 KB |
Output is correct |
21 |
Correct |
1 ms |
2908 KB |
Output is correct |
22 |
Correct |
1 ms |
2908 KB |
Output is correct |
23 |
Correct |
2 ms |
2904 KB |
Output is correct |
24 |
Correct |
1 ms |
2908 KB |
Output is correct |
25 |
Correct |
1 ms |
2908 KB |
Output is correct |
26 |
Correct |
14 ms |
9052 KB |
Output is correct |
27 |
Correct |
27 ms |
9308 KB |
Output is correct |
28 |
Correct |
29 ms |
9040 KB |
Output is correct |
29 |
Correct |
42 ms |
9096 KB |
Output is correct |
30 |
Correct |
31 ms |
9116 KB |
Output is correct |
31 |
Correct |
26 ms |
9308 KB |
Output is correct |
32 |
Correct |
8 ms |
9048 KB |
Output is correct |
33 |
Correct |
19 ms |
9168 KB |
Output is correct |
34 |
Correct |
24 ms |
9160 KB |
Output is correct |
35 |
Correct |
9 ms |
9052 KB |
Output is correct |
36 |
Correct |
19 ms |
9120 KB |
Output is correct |
37 |
Correct |
23 ms |
9128 KB |
Output is correct |
38 |
Correct |
25 ms |
9040 KB |
Output is correct |
39 |
Correct |
13 ms |
9052 KB |
Output is correct |
40 |
Correct |
10 ms |
9052 KB |
Output is correct |
41 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
16 ms |
612 KB |
Output is correct |
10 |
Correct |
5 ms |
604 KB |
Output is correct |
11 |
Correct |
11 ms |
1220 KB |
Output is correct |
12 |
Correct |
10 ms |
1248 KB |
Output is correct |
13 |
Correct |
13 ms |
1624 KB |
Output is correct |
14 |
Correct |
9 ms |
1116 KB |
Output is correct |
15 |
Correct |
3 ms |
632 KB |
Output is correct |
16 |
Correct |
10 ms |
1104 KB |
Output is correct |
17 |
Correct |
24 ms |
2388 KB |
Output is correct |
18 |
Correct |
13 ms |
1624 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
21 |
Correct |
2 ms |
2908 KB |
Output is correct |
22 |
Correct |
1 ms |
2904 KB |
Output is correct |
23 |
Correct |
1 ms |
2908 KB |
Output is correct |
24 |
Correct |
1 ms |
2904 KB |
Output is correct |
25 |
Correct |
2 ms |
3160 KB |
Output is correct |
26 |
Correct |
1 ms |
2908 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
2908 KB |
Output is correct |
29 |
Correct |
1 ms |
2908 KB |
Output is correct |
30 |
Correct |
1 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2908 KB |
Output is correct |
33 |
Correct |
1 ms |
2908 KB |
Output is correct |
34 |
Correct |
14 ms |
9052 KB |
Output is correct |
35 |
Correct |
27 ms |
9308 KB |
Output is correct |
36 |
Correct |
29 ms |
9040 KB |
Output is correct |
37 |
Correct |
42 ms |
9096 KB |
Output is correct |
38 |
Correct |
31 ms |
9116 KB |
Output is correct |
39 |
Correct |
26 ms |
9308 KB |
Output is correct |
40 |
Correct |
8 ms |
9048 KB |
Output is correct |
41 |
Correct |
19 ms |
9168 KB |
Output is correct |
42 |
Correct |
24 ms |
9160 KB |
Output is correct |
43 |
Correct |
9 ms |
9052 KB |
Output is correct |
44 |
Correct |
19 ms |
9120 KB |
Output is correct |
45 |
Correct |
23 ms |
9128 KB |
Output is correct |
46 |
Correct |
25 ms |
9040 KB |
Output is correct |
47 |
Correct |
13 ms |
9052 KB |
Output is correct |
48 |
Correct |
10 ms |
9052 KB |
Output is correct |
49 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |