This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 << "\n";
}
return 0;
}
Compilation message (stderr)
chessboard.cpp:33: warning: ignoring '#pragma omp parallel' [-Wunknown-pragmas]
33 | #pragma omp parallel for reduction(+:count)
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |