Submission #258028

# Submission time Handle Problem Language Result Execution time Memory
258028 2020-08-05T08:32:30 Z 문홍윤(#5065) Sandwich (JOI16_sandwich) C++17
100 / 100
3244 ms 7432 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int inf=2000000000;

int n, m;
char str[410][410];
int ans[410][410], sum;
int ch[410][410];
int mx[]={-1, 0, 1, 0}, my[]={0, 1, 0, -1};

void dfs(int x, int y, int dir){
    if(ch[x][y]==2||!str[x][y])return;
    if(ch[x][y]==1){
        sum=inf;
        return;
    }
    ch[x][y]=1;
    sum+=2;
    if(str[x][y]=='N'){
        if(dir<=1){
            dfs(x+mx[0], y+my[0], 0);
            dfs(x+mx[1], y+my[1], 1);
        }
        else{
            dfs(x+mx[2], y+my[2], 2);
            dfs(x+mx[3], y+my[3], 3);
        }
    }
    else{
        if(dir==0||dir==3){
            dfs(x+mx[0], y+my[0], 0);
            dfs(x+mx[3], y+my[3], 3);
        }
        else{
            dfs(x+mx[1], y+my[1], 1);
            dfs(x+mx[2], y+my[2], 2);
        }
    }
    ch[x][y]=2;
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++)scanf("%s", str[i]+1);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++)ans[i][j]=inf;
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            dfs(i, j, 3);
            ans[i][j]=min(ans[i][j], sum);
        }
        sum=0;
        memset(ch, 0, sizeof ch);
        for(int j=m; j>=1; j--){
            dfs(i, j, 1);
            ans[i][j]=min(ans[i][j], sum);
        }
        sum=0;
        memset(ch, 0, sizeof ch);
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++)printf("%d ", ans[i][j]==inf?-1:ans[i][j]);
        puts("");
    }
}

Compilation message

sandwich.cpp: In function 'int main()':
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:47:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=n; i++)scanf("%s", str[i]+1);
                            ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 8 ms 1152 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 4 ms 1024 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
12 Correct 3 ms 1024 KB Output is correct
13 Correct 6 ms 1152 KB Output is correct
14 Correct 6 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 9 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 5 ms 1152 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 7 ms 1152 KB Output is correct
25 Correct 8 ms 1152 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 5 ms 1152 KB Output is correct
28 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 8 ms 1152 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 4 ms 1024 KB Output is correct
10 Correct 6 ms 1152 KB Output is correct
11 Correct 6 ms 1152 KB Output is correct
12 Correct 3 ms 1024 KB Output is correct
13 Correct 6 ms 1152 KB Output is correct
14 Correct 6 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 9 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 5 ms 1152 KB Output is correct
22 Correct 5 ms 1152 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 7 ms 1152 KB Output is correct
25 Correct 8 ms 1152 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 5 ms 1152 KB Output is correct
28 Correct 5 ms 1152 KB Output is correct
29 Correct 1 ms 1024 KB Output is correct
30 Correct 20 ms 1792 KB Output is correct
31 Correct 3244 ms 7224 KB Output is correct
32 Correct 3184 ms 7432 KB Output is correct
33 Correct 707 ms 3144 KB Output is correct
34 Correct 909 ms 2680 KB Output is correct
35 Correct 740 ms 2424 KB Output is correct
36 Correct 40 ms 1912 KB Output is correct
37 Correct 1034 ms 2764 KB Output is correct
38 Correct 912 ms 2680 KB Output is correct
39 Correct 1028 ms 2808 KB Output is correct
40 Correct 1757 ms 2936 KB Output is correct
41 Correct 636 ms 2296 KB Output is correct
42 Correct 1280 ms 3080 KB Output is correct
43 Correct 1313 ms 3120 KB Output is correct
44 Correct 1328 ms 3192 KB Output is correct
45 Correct 842 ms 2680 KB Output is correct
46 Correct 541 ms 2808 KB Output is correct
47 Correct 707 ms 2748 KB Output is correct
48 Correct 419 ms 2552 KB Output is correct
49 Correct 570 ms 2680 KB Output is correct
50 Correct 645 ms 2648 KB Output is correct
51 Correct 558 ms 2680 KB Output is correct
52 Correct 584 ms 2680 KB Output is correct
53 Correct 554 ms 2808 KB Output is correct
54 Correct 536 ms 2808 KB Output is correct
55 Correct 571 ms 2808 KB Output is correct
56 Correct 554 ms 2808 KB Output is correct
57 Correct 456 ms 2552 KB Output is correct
58 Correct 1475 ms 3540 KB Output is correct
59 Correct 1509 ms 3376 KB Output is correct
60 Correct 1054 ms 3064 KB Output is correct
61 Correct 1608 ms 3064 KB Output is correct
62 Correct 775 ms 2900 KB Output is correct
63 Correct 957 ms 2920 KB Output is correct