답안 #1000042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000042 2024-06-16T13:53:10 Z vjudge1 Awesome Arrowland Adventure (eJOI19_adventure) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pf push_front
#define vi vector<int>
#define pi pair<int,int>
#define pii pair<int,pi>

const int MAX = 510;
int g[MAX][MAX];
const int mod = 4;

int dy[4]={1,0,-1,0};
int dx[4] ={0, 1,0,-1};
int dir[4] = {4,3,2,1};

int lmatch(char c){
    if(c=='E') return 1;
    else if(c=='S') return 2;
    else if(c=='W') return 3;
    else if(c=='N')return 4;
    return 5;
 }
 

int visited[MAX][MAX];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n,m;
    cin >> n >> m;
    char c;
    for(int i = 1; i<= n; i++){
        for(int j = 1; j<=m; j++){
            cin >> c;
            g[i][j] =lmatch(c);
        }
    }
    priority_queue<pii, vector<pii>, greater<pii>>pq;
    pq.push({0,{1,1}});
    ll ncost =0;
    int ans = INT_MAX;
    while(!pq.empty()){
        int curx = pq.top().s.f;
        int cury = pq.top().s.s;
        int cost = pq.top().f;
     //  cout << curx << " " << cury << endl;
     if(curx == n && cury == m){
            
            ans = min(ans, cost);
           //return 0;
        }
        
     pq.pop();
     if(visited[curx][cury])continue;
      visited[curx][cury]=1;
        
       
        int tox, toy;
        for(int i = 0; i <4 ; i++){
            tox = curx+dx[i], toy = cury+dy[i];
            
            
      //      cout << tox << " " << toy<< " " << curx << " ">>
             if(tox >  500|| toy >500|| tox <1|| toy < 1)continue;
             if(g[tox][toy]==0) continue;
            if(g[tox][toy]==5&& (tox!= n ||toy!=m)) continue;
           // if(visited[tox][toy]) continue;

            ncost =((dir[i]- g[curx][cury])+mod)%mod;
          

           pq.push({ncost+cost,{tox, toy}});
        }
      
    }
   
  
    if(ans==INT_MAX)  cout << -1<< endl;
    else cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -