Submission #878130

# Submission time Handle Problem Language Result Execution time Memory
878130 2023-11-24T05:49:43 Z AI_2512 Chessboard (IZhO18_chessboard) C++17
39 / 100
796 ms 262144 KB
#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;
    
        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 1 ms 348 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 756 KB Output is correct
4 Correct 2 ms 792 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 3 ms 804 KB Output is correct
7 Correct 1 ms 760 KB Output is correct
8 Correct 1 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 732 KB Output is correct
8 Correct 1 ms 604 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 436 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 684 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 732 KB Output is correct
8 Correct 1 ms 604 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 436 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 94 ms 33136 KB Output is correct
17 Correct 81 ms 36692 KB Output is correct
18 Correct 153 ms 36696 KB Output is correct
19 Correct 778 ms 34276 KB Output is correct
20 Correct 796 ms 34532 KB Output is correct
21 Correct 78 ms 36688 KB Output is correct
22 Correct 413 ms 36024 KB Output is correct
23 Correct 208 ms 34436 KB Output is correct
24 Correct 141 ms 36684 KB Output is correct
25 Correct 183 ms 34128 KB Output is correct
26 Correct 115 ms 33628 KB Output is correct
27 Correct 177 ms 34144 KB Output is correct
28 Correct 137 ms 33996 KB Output is correct
29 Correct 48 ms 34384 KB Output is correct
30 Correct 83 ms 34716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 756 KB Output is correct
4 Correct 2 ms 792 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 3 ms 804 KB Output is correct
7 Correct 1 ms 760 KB Output is correct
8 Correct 1 ms 772 KB Output is correct
9 Runtime error 102 ms 262144 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -