제출 #115018

#제출 시각아이디문제언어결과실행 시간메모리
115018onjo0127Sandwich (JOI16_sandwich)C++11
100 / 100
3649 ms8056 KiB
#include <bits/stdc++.h>
using namespace std;

char A[409][409];
int R, C, chk[409][409], s, ans[409][409];
const int INF = 1e9;

/*
0 - up
1 - down
2 - left
3 - right
*/
void go(int x, int y, int d) {
    if(x < 1 || x > R || y < 1 || y > C) return;
    if(chk[x][y] == 2) return;
    if(chk[x][y] == 1) {
        s = INF;
        return;
    }
    chk[x][y] = 1; s += 2;
    if(A[x][y] == 'N') {
        if(d == 0 || d == 3) {go(x-1, y, 0); go(x, y+1, 3);}
        if(d == 1 || d == 2) {go(x+1, y, 1); go(x, y-1, 2);}
    }
    if(A[x][y] == 'Z') {
        if(d == 0 || d == 2) {go(x-1, y, 0); go(x, y-1, 2);}
        if(d == 1 || d == 3) {go(x+1, y, 1); go(x, y+1, 3);}
    }
    chk[x][y] = 2;
}

void cl() {
    memset(chk, 0, sizeof(chk));
    s = 0;
}

int main() {
    scanf("%d%d",&R,&C);
    for(int i=1; i<=R; i++) {
        for(int j=1; j<=C; j++) {
            scanf(" %c",&A[i][j]);
        }
    }
    for(int i=1; i<=C; i++) {
        for(int j=1; j<=R; j++) {
            go(j, i, 0);
            ans[j][i] = s;
        }
        cl();
        for(int j=R; j>=1; j--) {
            go(j, i, 1);
            ans[j][i] = min(s, ans[j][i]);
        }
        cl();
    }
    for(int i=1; i<=R; i++) {
        for(int j=1; j<=C; j++) {
            if(ans[i][j] >= INF) printf("-1 ");
            else printf("%d ", ans[i][j]);
        }
        puts("");
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sandwich.cpp: In function 'int main()':
sandwich.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&R,&C);
     ~~~~~^~~~~~~~~~~~~~
sandwich.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&A[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...