#include<bits/stdc++.h>
#define inf 1e18
#define int long long
#define N 1010
using namespace std;
int v[N][N];
int mark[N][N];
int32_t main(){
int n, k;
cin >> n >> k;
if(n > N-1){
int res1 = 0;
res2 = 0;
if(n % 2 == 0){
res1 = 2;
res2 = 2;
}
else{
res1 = (p+1)/2;
res2 = (p-1)/2;
}
for(int i = 1;i <= k;i++){
int a, b, c, d;
cin >> a >> b >> c >> d;
if(a % 2 != b % 2){
res1--;
res2++;
}
else{
res1++;
res2--;
}
}
cout << min(res1, res2) << '\n';
}
// vector <pair <int, int>> v;
for(int i = 1;i <= k;i++){
int a, b, c, d;
cin >> a >> b >> c >> d;
v[a][b] = 1;
}
int res = inf;
for(int p = 1;p < n;p++){
if(n % p != 0) continue;
int resp = 0;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
int ti = (i-1)/p;
int tj = (j-1)/p;
if((ti % 2 )!= (tj % 2)){
if(v[i][j] != 0) resp++;
}
else{
if(v[i][j] != 1) resp++;
}
}
}
// cout << p << ' ' << resp << '\n';
res = min(res, resp);
resp = 0;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
int ti = (i-1)/p;
int tj = (j-1)/p;
if((ti % 2 )!= (tj % 2)){
if(v[i][j] != 1) resp++;
}
else{
if(v[i][j] != 0) resp++;
}
}
}
res = min(res, resp);
}
cout << res << '\n';
}
Compilation message
chessboard.cpp: In function 'int32_t main()':
chessboard.cpp:17:9: error: 'res2' was not declared in this scope; did you mean 'res1'?
17 | res2 = 0;
| ^~~~
| res1
chessboard.cpp:25:21: error: 'p' was not declared in this scope
25 | res1 = (p+1)/2;
| ^