Submission #776102

# Submission time Handle Problem Language Result Execution time Memory
776102 2023-07-07T10:12:52 Z vjudge1 Awesome Arrowland Adventure (eJOI19_adventure) C++17
22 / 100
1 ms 340 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,a,b;
char sor[505][505];

void dijk(){
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            uzak[i][j]=-1;
        }
    }
    priority_queue <pair<int,pair<int,int>>> q;//
    q.push({0,{0,0}});

    while(!q.empty()){
        int a=q.top().second.first;
        int b=q.top().second.second;
        int cost=q.top().first;
        q.pop();
        if((a<0 || a>=m || b<0 || b>=n)){//SINIR dışında
            continue;
        }
        if(uzak[b][a]!=-1) continue;
        uzak[b][a]=cost;
        if(dizi[b][a]==-1)continue;
        for(int i=0;i<4;i++){
            int gx=(dizi[b][a]+i)%4;
            int gy=(dizi[b][a]+i)%4;
            if(gx==0)gx=0;
            else if(gx==1)gx=1;
            else if(gx==2)gx=0;
            else if(gx==3)gx=-1;
//////////////////////////////////////////////////////////////
            if(gy==0)gy=-1;
            else if(gy==1)gy=0;
            else if(gy==2)gy=1;
            else if(gy==3)gy=0;
            q.push({-(cost+i),{a+gx,b+gy}});
        }
    }
}

int32_t main(){
    //  faster
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>sor[i][j];
            char h=sor[i][j];
            if(h=='N')dizi[i][j]=0;
            else if(h=='E')dizi[i][j]=1;
            else if(h=='S')dizi[i][j]=2;
            else if(h=='W')dizi[i][j]=3;
            else if(h=='X')dizi[i][j]=-1;
            uzak[i][j]=-1;
        }
    }
    if(n==1){
        cev=0;
        bool stop=true;
        for(int i=0;i<n && stop;i++){
            for(int j=0;j<m && stop;j++){
                if(sor[i][j]=='X'){
                    if(!(i==n-1 && j==m-1)){
                        cev=-1;
                        stop=false;
                    }
                }
                else if(sor[i][j]=='N'){
                    cev++;
                }
                else if(sor[i][j]=='S'){
                    cev+=3;
                }
                else if(sor[i][j]=='W'){
                    cev+=2;
                }
                else continue;
            }
        }
        cout<<cev<<'\n';
        return 0;
    }
    dijk();
   /* for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<uzak[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<-1*uzak[n-1][m-1]<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Incorrect 0 ms 340 KB Output isn't correct
23 Halted 0 ms 0 KB -