#include <iostream>
#include <vector>
#include <algorithm>
#define chkmin(a, b) a = min(a, b)
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int infinity = 1e9;
int ans = infinity;
int dir_x[] = {-1, 0, 1, 0};
int dir_y[] = {0, 1, 0, -1};
int n, m;
void Dfs(vvi &graph, int x, int y, vvb &visited, int count) {
if (x < 0 || x >= n || y < 0 || y >= m) return;
if (visited[x][y]) return;
if (x == n - 1 && y == m - 1) {
chkmin(ans, count);
return;
}
if (graph[x][y] == 4) return;
visited[x][y] = true;
for (int i = 0; i < 4; i++) {
Dfs(graph, x + dir_x[graph[x][y]], y + dir_y[graph[x][y]], visited, count + i);
graph[x][y]++;
graph[x][y] %= 4;
}
visited[x][y] = false;
}
int main() {
cin >> n >> m;
vvi graph(n, vi(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
if (c == 'X') {
graph[i][j] = 4;
} else if (c == 'S') {
graph[i][j] = 2;
} else if (c == 'W') {
graph[i][j] = 3;
} else if (c == 'E') {
graph[i][j] = 1;
}
}
}
vvb visited(n, vb(m));
Dfs(graph, 0, 0, visited, 0);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |