답안 #775916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775916 2023-07-07T07:04:08 Z vjudge1 Awesome Arrowland Adventure (eJOI19_adventure) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 1000000000005
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mid (start+end)/2
#define mod 1000000007
int n,m,dizi[505][505],uzak[505][505];
int cev=0,x,y;
map <pair<int,int>,int> mp;

void dfs(int i,int j){
    //cout<<"de "<<i<<" "<<j<<endl;
    mp[{i,j}]++;
    if((mp[{i,j}]>5)){
        cev=-1;
        return ;
    }
    if((i==n-1 && j==m-1)){
        return ;
    }
    if(dizi[i][j]==0)x=i-1,y=j;
    else if(dizi[i][j]==1)x=i,y=j+1;
    else if(dizi[i][j]==2)x=i+1,y=j;
    else if(dizi[i][j]==3)x=i,y=j-1;
    else {
        if(i==n-1 && j==m-1){
            return ;
        }
        dizi[i][j]++;
        if(dizi[i][j]==4)dizi[i][j]=0;
        cev++;
        dfs(i,j);
        //cev=-1;
        //return ;
    }
    //cout<<x<<" "<<y<<endl;
    if(x<0 || x>=n || y<0 || y>=n){
        dizi[i][j]++;
        if(dizi[i][j]==4)dizi[i][j]=0;
        cev++;
        //cout<<"icerde"<<x<<" "<<y<<" "<<cev<<endl;
        dfs(i,j);
        return ;
    }
    dfs(x,y);
}

int32_t main(){
    //faster
    cin>>n>>m;
    char c;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>c;
            if(c=='N')dizi[i][j]=0;
            else if(c=='E')dizi[i][j]=1;
            else if(c=='S')dizi[i][j]=2;
            else if(c=='W')dizi[i][j]=3;
            else if(c=='X')dizi[i][j]=-1;
        }
    }
    dfs(0,0);
    cout<<cev<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -