답안 #22516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22516 2017-04-30T05:16:34 Z 코졸부(#979, cprayer) Young Zebra (KRIII5_YZ) C++14
0 / 7
76 ms 102552 KB
#include <cstdio>

const int MAXN = 409, MAXM = 409;
const int cx[] = {1, 0, -1 ,0}, cy[] = {0, 1, 0, -1};
char A[MAXN * 9][MAXN * 9];
bool visited[MAXN * 9][MAXN * 9], visited2[MAXN * 9][MAXN * 9], check[256];
int cnt, ans[MAXN * 9][MAXN * 9];
int N, M;

int dfs1(int y, int x, char c){
    if(y >= N * 3 || y < 0 || x >= M * 3 || x < 0){
        if(y == N * 3 && A[0][x] == A[N * 3 - 1][x]) check[c] = true;
        if(x == M * 3 && A[y][0] == A[y][M * 3 - 1]) check[c] = true;
        return 0;
    }
    if(visited[y][x] || A[y][x] != c) return 0;
    int res = 1;
    visited[y][x] = true;
    for(int i = 0; i < 4; i++) res += dfs1(y + cy[i], x + cx[i], c);
    return check[c] ? -1 : res;
}

void dfs2(int y, int x, char c, int v){
    if(y >= N * 3 || y < 0 || x >= M * 3 || x < 0) return;
    if(visited2[y][x] || A[y][x] != c) return;
    visited2[y][x] = true;
    for(int i = 0; i < 4; i++) dfs2(y + cy[i], x + cx[i], c, v);
    ans[y][x] = v;
}

int main(){
    scanf("%d%d%*c", &N, &M);
    for(int i = 0; i < N; i++){
        scanf("%s", A[i]);
        for(int j = 0; j < M; j++){
            for(int v = 0; v < 3; v++){
                for(int w = 0; w < 3; w++) A[v * N + i][w * M + j] = A[i][j];
            }
        }
    }
    //for(int i = 0; i < N * 3; i++) printf("%s\n", A[i]); 
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            int y = i + N, x = j + M;
            check[A[y][x]] = false;
            cnt = 0;
            if(!visited[y][x]) dfs2(y, x, A[y][x], dfs1(y, x, A[y][x]));
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++) printf("%d ", ans[i + N][j + M]);
        printf("\n");
    }
}

Compilation message

YZ.cpp: In function 'int dfs1(int, int, char)':
YZ.cpp:12:61: warning: array subscript has type 'char' [-Wchar-subscripts]
         if(y == N * 3 && A[0][x] == A[N * 3 - 1][x]) check[c] = true;
                                                             ^
YZ.cpp:13:61: warning: array subscript has type 'char' [-Wchar-subscripts]
         if(x == M * 3 && A[y][0] == A[y][M * 3 - 1]) check[c] = true;
                                                             ^
YZ.cpp:20:19: warning: array subscript has type 'char' [-Wchar-subscripts]
     return check[c] ? -1 : res;
                   ^
YZ.cpp: In function 'int main()':
YZ.cpp:45:26: warning: array subscript has type 'char' [-Wchar-subscripts]
             check[A[y][x]] = false;
                          ^
YZ.cpp:32:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%*c", &N, &M);
                             ^
YZ.cpp:34:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", A[i]);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 76 ms 100092 KB Output is partially correct
2 Incorrect 66 ms 102552 KB Output isn't correct
3 Halted 0 ms 0 KB -