Submission #258036

# Submission time Handle Problem Language Result Execution time Memory
258036 2020-08-05T08:39:59 Z 반딧불(#5055) Sandwich (JOI16_sandwich) C++17
100 / 100
4368 ms 15864 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 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(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;
    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 j=1; j<=m; j++){
        int tmp = 0;
        memset(visited, 0, sizeof(visited));
        for(int i=n; i>=1; i--){
            tmp += dfs(i, j, 0);
            if(tmp >= 1e9) break;
            ans[i][j] = min(ans[i][j], tmp);
        }

        tmp = 0;
        memset(visited, 0, sizeof(visited));
        for(int i=1; i<=n; i++){
            tmp += dfs(i, j, 1);
            if(tmp >= 1e9) break;
            ans[i][j] = min(ans[i][j], tmp);
        }
    }

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

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:46:36: warning: format '%c' expects argument of type 'char*', but argument 2 has type 'int*' [-Wformat=]
             scanf(" %c", &arr[i][j]);
                          ~~~~~~~~~~^
sandwich.cpp:43: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:46: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 2 ms 1024 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 7 ms 1152 KB Output is correct
8 Correct 8 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 12 ms 1152 KB Output is correct
11 Correct 9 ms 1152 KB Output is correct
12 Correct 8 ms 1024 KB Output is correct
13 Correct 7 ms 1152 KB Output is correct
14 Correct 7 ms 1152 KB Output is correct
15 Correct 6 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 7 ms 1152 KB Output is correct
18 Correct 7 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 6 ms 1152 KB Output is correct
23 Correct 5 ms 1152 KB Output is correct
24 Correct 10 ms 1192 KB Output is correct
25 Correct 7 ms 1152 KB Output is correct
26 Correct 8 ms 1152 KB Output is correct
27 Correct 12 ms 1184 KB Output is correct
28 Correct 11 ms 1384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 7 ms 1152 KB Output is correct
8 Correct 8 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 12 ms 1152 KB Output is correct
11 Correct 9 ms 1152 KB Output is correct
12 Correct 8 ms 1024 KB Output is correct
13 Correct 7 ms 1152 KB Output is correct
14 Correct 7 ms 1152 KB Output is correct
15 Correct 6 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 7 ms 1152 KB Output is correct
18 Correct 7 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 6 ms 1152 KB Output is correct
23 Correct 5 ms 1152 KB Output is correct
24 Correct 10 ms 1192 KB Output is correct
25 Correct 7 ms 1152 KB Output is correct
26 Correct 8 ms 1152 KB Output is correct
27 Correct 12 ms 1184 KB Output is correct
28 Correct 11 ms 1384 KB Output is correct
29 Correct 20 ms 1024 KB Output is correct
30 Correct 1 ms 2176 KB Output is correct
31 Correct 56 ms 2808 KB Output is correct
32 Correct 48 ms 2784 KB Output is correct
33 Correct 14 ms 2176 KB Output is correct
34 Correct 1625 ms 3208 KB Output is correct
35 Correct 1364 ms 2780 KB Output is correct
36 Correct 3 ms 2304 KB Output is correct
37 Correct 2151 ms 3232 KB Output is correct
38 Correct 1653 ms 3216 KB Output is correct
39 Correct 1896 ms 3320 KB Output is correct
40 Correct 2247 ms 3424 KB Output is correct
41 Correct 1593 ms 2552 KB Output is correct
42 Correct 2369 ms 3704 KB Output is correct
43 Correct 2335 ms 3672 KB Output is correct
44 Correct 2306 ms 3576 KB Output is correct
45 Correct 1632 ms 3196 KB Output is correct
46 Correct 1031 ms 3320 KB Output is correct
47 Correct 1174 ms 3252 KB Output is correct
48 Correct 696 ms 2936 KB Output is correct
49 Correct 1036 ms 3320 KB Output is correct
50 Correct 1225 ms 3452 KB Output is correct
51 Correct 1088 ms 3320 KB Output is correct
52 Correct 1029 ms 3200 KB Output is correct
53 Correct 984 ms 3320 KB Output is correct
54 Correct 941 ms 3200 KB Output is correct
55 Correct 1000 ms 3204 KB Output is correct
56 Correct 1044 ms 3200 KB Output is correct
57 Correct 703 ms 2936 KB Output is correct
58 Correct 2228 ms 3460 KB Output is correct
59 Correct 2211 ms 3476 KB Output is correct
60 Correct 1471 ms 3072 KB Output is correct
61 Correct 1686 ms 3576 KB Output is correct
62 Correct 3298 ms 3320 KB Output is correct
63 Correct 4368 ms 15864 KB Output is correct