#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 600
vector < vector < int >> g(MAX, vector < int > (MAX, 0));
vector < vector < int >> dist(MAX, vector < int > (MAX, -1));
int dx[4] = {
0,
1,
0 - 1
}, dy[4] = {
-1,
0,
1,
0
}, n, m;
void dj() {
priority_queue < pair < int, pair < int, int >> , vector < pair < int, pair < int, int >> > , greater < pair < int, pair < int, int > > > > pq;
pq.push(make_pair(0, make_pair(0, 0)));
while (!pq.empty()) {
int x = pq.top().second.first, y = pq.top().second.second, c = pq.top().first;
pq.pop();
if (x < 0 || x >= m || y < 0 || y >= n || dist[y][x] != -1) continue;
dist[y][x] = c;
if (g[y][x] == -1) continue;
for (int i = 0; i < 4; i++) pq.push(make_pair(c + i, make_pair(x + dx[(g[y][x] + i) % 4], y + dy[(g[y][x] + i) % 4])));
}
}
int32_t main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
if (c == 'N') g[i][j] = 0;
if (c == 'E') g[i][j] = 1;
if (c == 'S') g[i][j] = 2;
if (c == 'W') g[i][j] = 3;
else if (c == 'X') g[i][j] = -1;
}
}
dj();
cout << dist[n - 1][m - 1] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
4 ms |
5964 KB |
Output is correct |
3 |
Correct |
4 ms |
5964 KB |
Output is correct |
4 |
Correct |
4 ms |
5964 KB |
Output is correct |
5 |
Correct |
3 ms |
5964 KB |
Output is correct |
6 |
Correct |
4 ms |
5964 KB |
Output is correct |
7 |
Correct |
3 ms |
5964 KB |
Output is correct |
8 |
Correct |
4 ms |
5964 KB |
Output is correct |
9 |
Correct |
4 ms |
5964 KB |
Output is correct |
10 |
Correct |
4 ms |
5964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
4 ms |
5964 KB |
Output is correct |
3 |
Correct |
4 ms |
5964 KB |
Output is correct |
4 |
Correct |
4 ms |
5964 KB |
Output is correct |
5 |
Correct |
3 ms |
5964 KB |
Output is correct |
6 |
Correct |
4 ms |
5964 KB |
Output is correct |
7 |
Correct |
3 ms |
5964 KB |
Output is correct |
8 |
Correct |
4 ms |
5964 KB |
Output is correct |
9 |
Correct |
4 ms |
5964 KB |
Output is correct |
10 |
Correct |
4 ms |
5964 KB |
Output is correct |
11 |
Correct |
4 ms |
5964 KB |
Output is correct |
12 |
Correct |
4 ms |
5964 KB |
Output is correct |
13 |
Correct |
4 ms |
5964 KB |
Output is correct |
14 |
Correct |
3 ms |
5964 KB |
Output is correct |
15 |
Correct |
3 ms |
5964 KB |
Output is correct |
16 |
Correct |
4 ms |
5964 KB |
Output is correct |
17 |
Correct |
4 ms |
5964 KB |
Output is correct |
18 |
Correct |
4 ms |
5964 KB |
Output is correct |
19 |
Correct |
4 ms |
5964 KB |
Output is correct |
20 |
Correct |
4 ms |
5964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
5964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Incorrect |
4 ms |
5964 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5964 KB |
Output is correct |
2 |
Correct |
4 ms |
5964 KB |
Output is correct |
3 |
Correct |
4 ms |
5964 KB |
Output is correct |
4 |
Correct |
4 ms |
5964 KB |
Output is correct |
5 |
Correct |
3 ms |
5964 KB |
Output is correct |
6 |
Correct |
4 ms |
5964 KB |
Output is correct |
7 |
Correct |
3 ms |
5964 KB |
Output is correct |
8 |
Correct |
4 ms |
5964 KB |
Output is correct |
9 |
Correct |
4 ms |
5964 KB |
Output is correct |
10 |
Correct |
4 ms |
5964 KB |
Output is correct |
11 |
Correct |
4 ms |
5964 KB |
Output is correct |
12 |
Correct |
4 ms |
5964 KB |
Output is correct |
13 |
Correct |
4 ms |
5964 KB |
Output is correct |
14 |
Correct |
3 ms |
5964 KB |
Output is correct |
15 |
Correct |
3 ms |
5964 KB |
Output is correct |
16 |
Correct |
4 ms |
5964 KB |
Output is correct |
17 |
Correct |
4 ms |
5964 KB |
Output is correct |
18 |
Correct |
4 ms |
5964 KB |
Output is correct |
19 |
Correct |
4 ms |
5964 KB |
Output is correct |
20 |
Correct |
4 ms |
5964 KB |
Output is correct |
21 |
Incorrect |
4 ms |
5964 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |