#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
#define ll long long int
ll n, k;
vector<int> chess[maxn];
void solve_k0(){
ll minimo = 999999;
for(int i = 1; i < n; i++){
if(n % i != 0) continue;
int test = i*i;
minimo = min(minimo, ((n*n/test)/2)*test);
}
cout << minimo << endl;
}
int block(ll number, ll siz){
return ((n-1)/siz + 1)%2;
}
ll solve_square(ll siz){
ll cont = 0;
for(int i = 1; i <= n; i++){
ll cont_errado = 0, cont_certo = 0;
for(int j = 0; j < chess[i].size(); j++){
//if((i+j)%2 == chess[i][j]) cont_errado++;
int row = chess[i][j];
if(block(i, siz) == block(j, siz)) cont_certo++;
else cont_errado++;
}
cont += cont_errado + n/2 + i%2 - cont_certo;
}
return min(cont, n*n - cont);
}
int main(){
memset(chess, 0, sizeof chess);
cin >> n >> k;
if(k == 0) solve_k0();
else{
for(int i = 0; i < k; i++){
int x, y, l, m;
cin >> x >> y;
cin >> l >> m; //8)
chess[x].push_back(y);
}
ll minimo = 999999999999;
for(ll i = 1; i < n; i++){
if(i%n) minimo = min(minimo, solve_square(i));
}
}
return 0;
}
Compilation message
chessboard.cpp: In function 'long long int solve_square(long long int)':
chessboard.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int j = 0; j < chess[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~~
chessboard.cpp:25:8: warning: unused variable 'row' [-Wunused-variable]
25 | int row = chess[i][j];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
151 ms |
3892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
151 ms |
3892 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Incorrect |
151 ms |
3892 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |