Submission #314405

#TimeUsernameProblemLanguageResultExecution timeMemory
314405uroskAwesome Arrowland Adventure (eJOI19_adventure)C++14
34 / 100
1 ms640 KiB
#include <bits/stdc++.h> #include <chrono> #define ll long long #define ull unsigned long long #define ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define inf 1e15 #define pb push_back #define popb pop_back #define fi first #define sc second using namespace std; using namespace std::chrono; /*auto start = high_resolution_clock::now(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); cout << "Time taken by function: " << duration.count() << " microseconds" << endl;*/ const int maxn = 505; int maxi = 500*500+1; string a[maxn]; int n,m; map<char,map<char,int> > mp; int calc(int i,int j,int c,int bio[maxn][maxn]){ if((i==n-1&&j==n-1)==true) return c; if(a[i][j]=='X') return maxi; int x=maxi,y=maxi,z=maxi,w=maxi; if(i<n-1&&bio[i+1][j]==0){ bio[i+1][j]=1; if(a[i][j]!='S'||a[i][j]=='X') x = calc(i+1,j,c+mp[a[i][j]]['S'],bio); else x = calc(i+1,j,c,bio); bio[i+1][j]=0; } if(i>0&&bio[i-1][j]==0){ bio[i-1][j]=1; if(a[i][j]!='N'||a[i][j]=='X') y = calc(i-1,j,c+mp[a[i][j]]['N'],bio); else y =calc(i-1,j,c,bio); bio[i-1][j]=0; } if(j>0&&bio[i][j-1]==0){ bio[i][j-1]=1; if(a[i][j]!='W'||a[i][j]=='X') z = calc(i,j-1,c+mp[a[i][j]]['W'],bio); else z = calc(i,j-1,c,bio); bio[i][j-1]=0; } if(j<m-1&&bio[i][j+1]==0){ bio[i][j+1]=1; if(a[i][j]!='E'||a[i][j]=='X') w = calc(i,j+1,c+mp[a[i][j]]['E'],bio); else w = calc(i,j+1,c,bio); bio[i][j+1]=0; } return min(x,min(y,min(z,w))); } int main(){ cin >> n>> m; int k[maxn][maxn]; for(int i = 0;i<n;i++){ cin >> a[i]; } mp['N']['E']=1; mp['N']['S']=2; mp['N']['W']=3; mp['E']['S']=1; mp['E']['W']=2; mp['E']['N']=3; mp['S']['W']=1; mp['S']['N']=2; mp['S']['E']=3; mp['W']['N']=1; mp['W']['E']=2; mp['W']['S']=3; if(n==1){ string s = a[0]; int ans = 0; for(int i = 0;i<m-1;i++){ if(s[i]=='X') { cout<<"-1"; goto Next; } if(s[i]!='E'){ ans+=4-mp['E'][s[i]]; } } cout<<ans; Next:; }else{ int ans = calc(0,0,0,k); if(ans==maxi) printf("-1"); else printf("%d",ans); } }

Compilation message (stderr)

adventure.cpp:5:9: warning: ISO C++11 requires whitespace after the macro name
    5 | #define ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
      |         ^~~~~~~~
#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...