Submission #258023

# Submission time Handle Problem Language Result Execution time Memory
258023 2020-08-05T08:26:32 Z 반딧불(#5055) Sandwich (JOI16_sandwich) C++17
0 / 100
5 ms 1280 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
int arr[405][405];
int xx[]={0, 1, 0, -1}, yy[]={1, 0, -1, 0}; /// R, D, L, U

int visited[405][405];
int done[405][405][2];
int ans[405][405];

const int LINK[2][2][2] = { /// 'N' = 0, 'Z' = 1 | up : 0, down : 1 (input)
    1, 2,
    0, 3,
    0, 1,
    2, 3
};
const int DIR[2][4] = { /// ���, ����
    0, 1, 1, 0,
    1, 1, 0, 0
};

int dfs(int x, int y, int t){
    if(done[x][y][t]) return done[x][y][t];
    if(visited[x][y]){
        return visited[x][y] == 1 ? 1e9 : 0;
    }
    visited[x][y] = 1;
    int ret = 2;
    for(int i=0; i<2; i++){
        int d = LINK[arr[x][y]][t][i];
        int tx = x+xx[d], ty = y+yy[d];
        if(tx < 1 || tx > n || ty < 1 || ty > m) continue;
        ret += dfs(tx, ty, DIR[arr[tx][ty]][2^d]);
        if(ret >= 1e9) return 1e9;
    }
    visited[x][y] = 2;
    done[x][y][t] = ret;
    return ret;
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            scanf(" %c", &arr[i][j]);
            if(arr[i][j] == 'N') arr[i][j] = 0;
            else arr[i][j] = 1;
            ans[i][j] = 1e9;
        }
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            for(int t=0; t<=1; t++){
                memset(visited, 0, sizeof(visited));
                ans[i][j] = min(ans[i][j], dfs(i, j, t));
            }
            printf("%d ", ans[i][j] == 1e9 ? -1 : ans[i][j]);
        }
        puts("");
    }
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:49:36: warning: format '%c' expects argument of type 'char*', but argument 2 has type 'int*' [-Wformat=]
             scanf(" %c", &arr[i][j]);
                          ~~~~~~~~~~^
sandwich.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
sandwich.cpp:49:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &arr[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 4 ms 1024 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Incorrect 5 ms 1152 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 4 ms 1024 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Incorrect 5 ms 1152 KB Output isn't correct
6 Halted 0 ms 0 KB -