BOJ 25682 체스판 다시 칠하기 2

1 개요[ | ]

BOJ 25682 체스판 다시 칠하기 2


2 같이 보기[ | ]

3 C++[ | ]

#include <iostream>

using namespace std;

int N, M, K;
int A[2000][2000];
int B[2001][2001];
int C[2001][2001];

int main() {
    cin >> N >> M >> K;
    string temp;
    getline(cin, temp);
    for(int i=0; i<N; i++) {
        getline(cin, temp);
        for(int j=0; j<M; j++) {
            if(temp[j] == 'W') {
                A[i][j] = 1;
            }
        }
    }
    int temp1, temp2;
    for (int i=0; i<N; i++) {
        for (int j=0; j<M; j++) {
            temp1 = (i+j)%2==0 ? A[i][j] : !A[i][j];
            temp2 = (i+j)%2==0 ? !A[i][j] : A[i][j];
            B[i+1][j+1] = B[i+1][j] + B[i][j+1] - B[i][j] + temp1;
            C[i+1][j+1] = C[i+1][j] + C[i][j+1] - C[i][j] + temp2;
        }
    }
    int answer = 9000000;
    for (int i=1; i<=N-K+1; i++) {
        for (int j=1; j<=M-K+1; j++) {
            temp1 = B[i+K-1][j+K-1] - B[i+K-1][j-1] - B[i-1][j+K-1] + B[i-1][j-1];
            temp2 = C[i+K-1][j+K-1] - C[i+K-1][j-1] - C[i-1][j+K-1] + C[i-1][j-1];
            answer = min(answer, temp1);
            answer = min(answer, temp2);
        }
    }
    cout << answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}