Submission #750198

#TimeUsernameProblemLanguageResultExecution timeMemory
750198JassarAwesome Arrowland Adventure (eJOI19_adventure)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define f first #define s second using namespace std; int a[505][505]; int n,m; bool vis[505][505]; bool valid (int x , int y) { if (0 > x || 0 > y || x >= n || y >= m || a[x][y] == -1 || vis[x][y] == 1) return 0; return 1; } int ans = INT_MAX; void dfs (int x , int y, int cur) { if (x == n - 1 && y == m - 1) { ans = min(ans , cur); return ; } if (!valid(x , y)) return ; vis[x][y] = 1; int i = x , j = y; int u; if (a[i][j] == 3) u = 3; else if (a[i][j] == 2) u = 2; else if (a[i][j] == 1) u = 1; else u = 0; dfs(x , y - 1 , cur + u); if (a[i][j] == 2) u = 3; else if (a[i][j] == 1) u = 2; else if (a[i][j] == 0) u = 1; else u = 0; dfs(x - 1 , y , cur + u); if (a[i][j] == 1) u = 3; else if (a[i][j] == 0) u = 2; else if (a[i][j] == 3) u = 1; else u = 0; dfs(x , y + 1 , cur + u); if (a[i][j] == 0) u = 3; else if (a[i][j] == 3) u = 2; else if (a[i][j] == 2) u = 1; else u = 0; dfs(x + 1 , y , cur + u); vis[x][y] = 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=0; n>i; i++) { string y; cin >> y; for (int j=0; m>j; j++) { if (y[j] == 'W') a[i][j] = 0; else if (y[j] == 'N') a[i][j] = 3; else if (y[j] == 'E') a[i][j] = 2; else if (y[j] == 'S') a[i][j] = 1; else a[i][j] = -1; } } dfs(0 , 0 , 0); cout << ans << endl; return 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...