Submission #1056950

#TimeUsernameProblemLanguageResultExecution timeMemory
1056950goduadzesabaAwesome Arrowland Adventure (eJOI19_adventure)C++17
100 / 100
62 ms28140 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N=505,mod=1e9+7; int n,m,x,y[5],d[N*N]; char ch; vector <pair<int,int> > v[N*N]; set <pair<int,int> > s; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for (int i=0; i<n; i++) for (int j=0; j<m; j++){ cin>>ch; d[i*m+j]=1e18; if (ch=='N'){ y[0]=3; y[1]=1; y[2]=0; y[3]=2; } if (ch=='S'){ y[0]=1; y[1]=3; y[2]=2; y[3]=0; } if (ch=='E'){ y[0]=2; y[1]=0; y[2]=3; y[3]=1; } if (ch=='W'){ y[0]=0; y[1]=2; y[2]=1; y[3]=3; } if (ch!='X'){ if (j>0) v[i*m+j].push_back({i*m+j-1,y[0]}); if (j<m-1) v[i*m+j].push_back({i*m+j+1,y[1]}); if (i>0) v[i*m+j].push_back({(i-1)*m+j,y[2]}); if (i<n-1) v[i*m+j].push_back({(i+1)*m+j,y[3]}); } } s.insert({0,0}); d[0]=0; while (!s.empty()){ x=s.begin()->second; s.erase(s.begin()); for (auto i:v[x]){ if (d[i.first]>d[x]+i.second){ s.erase({d[i.first],i.first}); d[i.first]=d[x]+i.second; s.insert({d[i.first],i.first}); } } } cout<<(d[n*m-1]==1e18?-1:d[n*m-1]); }
#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...