Submission #447632

#TimeUsernameProblemLanguageResultExecution timeMemory
447632idasAwesome Arrowland Adventure (eJOI19_adventure)C++11
38 / 100
2 ms2380 KiB
#include <bits/stdc++.h> #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) #define F first #define S second #define PB push_back #define MP make_pair #define SZ(x) ((int)((x).size())) #define LE(vec) vec[vec.size()-1] #define TSTS int t; cin >> t; while(t--)solve() const int INF = 1e9; const long long LINF = 1e18; const long double PI = asin(1)*2; const int MOD = 1e9+7; using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef map<int, int> mii; typedef long long ll; typedef long double ld; void setIO() { FAST_IO; } const int N=510; int m, n, d[N][N], g[N][N]; bool v[N][N]; priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> q; /* -1-X 0-N 1-E 2-S 3-W */ int c(char x) { if(x=='X') return -1; if(x=='N') return 0; if(x=='E') return 1; if(x=='S') return 2; if(x=='W') return 3; } pii re(int p, int x, int y) { if(p==0) return MP(x, y-1); if(p==1) return MP(x+1, y); if(p==2) return MP(x, y+1); if(p==3) return MP(x-1, y); } int main() { setIO(); cin >> m >> n; FOR(i, 0, m) { FOR(j, 0, n) { char x; cin >> x; g[j][i]=c(x); } } FOR(i, 0, m) FOR(j, 0, n) d[j][i]=INF; v[n-1][m-1]=true; d[0][0]=0; q.push(MP(0, MP(0, 0))); while(!q.empty()) { int k=q.top().F, x=q.top().S.F, y=q.top().S.S; if(!v[x][y]) { v[x][y]=true; FOR(i, 0, 4) { int nx=re((g[x][y]+i)%4, x, y).F, ny=re((g[x][y]+i)%4, x, y).S; if(nx<0 || nx>=n || ny<0 || ny>=m || (g[nx][ny]==-1 && (nx!=n-1 || ny!=m-1))) continue; d[nx][ny]=min(d[nx][ny], k+i); q.push(MP(d[nx][ny], MP(nx, ny))); } } q.pop(); } cout << (d[n-1][m-1]==INF?-1:d[n-1][m-1]); }

Compilation message (stderr)

adventure.cpp: In function 'int c(char)':
adventure.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^
adventure.cpp: In function 'pii re(int, int, int)':
adventure.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
   58 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...