답안 #878108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878108 2023-11-24T05:35:27 Z AI_2512 Chessboard (IZhO18_chessboard) C++17
31 / 100
849 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;
    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

chessboard.cpp:33: warning: ignoring '#pragma omp parallel' [-Wunknown-pragmas]
   33 |     #pragma omp parallel for reduction(+:count)
      |
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 98 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 3 ms 680 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 696 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 436 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 604 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 3 ms 680 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 696 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 436 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 604 KB Output is correct
14 Correct 2 ms 856 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 95 ms 33132 KB Output is correct
17 Correct 98 ms 37052 KB Output is correct
18 Correct 166 ms 37924 KB Output is correct
19 Correct 811 ms 34712 KB Output is correct
20 Correct 849 ms 34900 KB Output is correct
21 Correct 99 ms 36948 KB Output is correct
22 Correct 427 ms 36044 KB Output is correct
23 Correct 219 ms 34672 KB Output is correct
24 Correct 148 ms 37304 KB Output is correct
25 Correct 190 ms 34000 KB Output is correct
26 Correct 120 ms 33916 KB Output is correct
27 Correct 184 ms 34664 KB Output is correct
28 Correct 144 ms 34564 KB Output is correct
29 Correct 50 ms 34384 KB Output is correct
30 Correct 90 ms 34640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 98 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -