#include <bits/stdc++.h>
#include <omp.h>
using namespace std;
vector<vector<vector<int>>> generateChessboard(int boardSize, int squareWidth, int squareHeight) {
vector<vector<int>> chessboard1;
vector<vector<int>> chessboard2;
for (int i = 0; i < boardSize; ++i) {
vector<int> row;
vector<int> row2;
for (int j = 0; j < boardSize; ++j) {
int squareValue = (i / squareHeight + j / squareWidth) % 2;
int squareValue2 = ((i / squareHeight + j / squareWidth)+1) % 2;
row.push_back(squareValue);
row2.push_back(squareValue2);
}
chessboard1.push_back(row);
chessboard2.push_back(row2);
}
return {chessboard1, chessboard2};
}
int countdif(const vector<vector<int>>& matrix1, const vector<vector<int>>& matrix2){
int count = 0;
const size_t numRows = matrix1.size();
const size_t numCols = matrix1[0].size();
#pragma omp parallel for reduction(+:count)
for (size_t i = 0; i < numRows; ++i) {
for (size_t j = 0; j < numCols; ++j) {
if (matrix1[i][j] != matrix2[i][j]) {
count++;
}
}
}
return count;
}
int main(){
int n,k;
cin >> n >>k;
if (k == 0){
cout << (int) n*n / 2;
}
else{
vector<vector<int>> board(n, vector<int>(n, 0));
vector<vector<int>> board2;
for (int i = 0; i< k; i++){
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
for (int j = x1-1; j<=x2-1; j++){
for (int b = y1-1; b <=y2-1; b++){
board[j][b] = 1;
}
}
}
int min1 = n*n;
int nada = n/2;
for (int h = 1; h <= nada; h++){
if (n%h == 0){
min1 = min(min1,min(countdif(board, generateChessboard(n, h,h)[0]), countdif(board, generateChessboard(n, h,h)[1])));
}
}
cout << min1;
}
return 0;
}
Compilation message
chessboard.cpp:33: warning: ignoring '#pragma omp parallel' [-Wunknown-pragmas]
33 | #pragma omp parallel for reduction(+:count)
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
103 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
656 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
732 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
772 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
656 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
732 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
772 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
98 ms |
32620 KB |
Output is correct |
17 |
Correct |
91 ms |
35580 KB |
Output is correct |
18 |
Correct |
160 ms |
35700 KB |
Output is correct |
19 |
Correct |
830 ms |
33296 KB |
Output is correct |
20 |
Correct |
832 ms |
33340 KB |
Output is correct |
21 |
Correct |
81 ms |
35692 KB |
Output is correct |
22 |
Correct |
407 ms |
36040 KB |
Output is correct |
23 |
Correct |
221 ms |
33872 KB |
Output is correct |
24 |
Correct |
142 ms |
35700 KB |
Output is correct |
25 |
Correct |
191 ms |
34052 KB |
Output is correct |
26 |
Correct |
120 ms |
32992 KB |
Output is correct |
27 |
Correct |
175 ms |
33404 KB |
Output is correct |
28 |
Correct |
156 ms |
33076 KB |
Output is correct |
29 |
Correct |
62 ms |
33876 KB |
Output is correct |
30 |
Correct |
79 ms |
34536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
103 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |