Submission #258011

# Submission time Handle Problem Language Result Execution time Memory
258011 2020-08-05T08:14:16 Z 문홍윤(#5065) Sandwich (JOI16_sandwich) C++17
0 / 100
3 ms 1024 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
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 nw, int dir){
    if(ch[x][y]==nw){
        sum=inf;
        return;
    }
    if(ch[x][y]||!str[x][y])return;
    ch[x][y]=nw;
    sum=min(sum+2, inf);
    if(str[x][y]=='N'){
        if(dir<=1){
            dfs(x+mx[0], y+my[0], nw, 0);
            dfs(x+mx[1], y+my[1], nw, 1);
        }
        else{
            dfs(x+mx[2], y+my[2], nw, 2);
            dfs(x+mx[3], y+my[3], nw, 3);
        }
    }
    else{
        if(dir==0||dir==3){
            dfs(x+mx[0], y+my[0], nw, 0);
            dfs(x+mx[3], y+my[3], nw, 3);
        }
        else{
            dfs(x+mx[1], y+my[1], nw, 1);
            dfs(x+mx[2], y+my[2], nw, 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++){
            if(str[i][j]=='N')dfs(i, j, j, 2);
            else dfs(i, j, j, 0);
            ans[i][j]=min(ans[i][j], sum);
        }
        sum=0;
        memset(ch, 0, sizeof ch);
        for(int j=m; j>=1; j--){
            if(str[i][j]=='Z')dfs(i, j, j, 2);
            else dfs(i, j, j, 0);
            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:59: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:60: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 Incorrect 3 ms 1024 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 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 Incorrect 3 ms 1024 KB Output isn't correct
6 Halted 0 ms 0 KB -