Submission #1055074

#TimeUsernameProblemLanguageResultExecution timeMemory
1055074ThommyDBAwesome Arrowland Adventure (eJOI19_adventure)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; int m, n; vector<vector<int>> grid; vector<vector<int>> test; int dfs(int x, int y, int turns){ test[x][y]=min(test[x][y], turns); if(x==m-1 && y==n-1) return turns; if(grid[x][y]==-1)return 1e9; int dir = grid[x][y]; int ans = 1e9; if(x!=0)if(turns < test[x-1][y]) ans = min(ans, dfs(x-1, y, turns + (4>=dir?4-dir:4+4-dir))); // west if(x!=m-1)if(turns < test[x+1][y]) ans = min(ans, dfs(x+1, y, turns + (2>=dir?2-dir:2+4-dir))); // east if(y!=0)if(turns < test[x][y-1]) ans = min(ans, dfs(x, y-1, turns + (1>=dir?1-dir:1+4-dir))); // north if(y!=n-1)if(turns < test[x][y+1]) ans = min(ans, dfs(x, y+1, turns + (3>=dir?3-dir:3+4-dir))); // south return ans; } signed main(){ cin >> m >> n; grid.resize(m, vector<int>(n)); test.resize(m, vector<int>(n, 1e9)); for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ char dir; cin >> dir; if(dir=='N') grid[j][i] = 1; else if(dir=='E') grid[j][i] = 2; else if(dir=='S') grid[j][i] = 3; else if(dir=='W') grid[j][i] = 4; else grid[j][i]=-1; } } int ans = dfs(0, 0, 0); if(ans==1e9){ cout << "No\n"; } else{ cout << ans << "\n"; } }
#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...