Submission #984129

# Submission time Handle Problem Language Result Execution time Memory
984129 2024-05-16T10:26:14 Z Nomio Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
77 ms 5068 KB
//#include <bits/stdc++.h>
//using namespace std;
//int main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	int m, n;
//	cin >> m >> n;
//	string s[m];
//	for(int i = 0; i < m; i++) {
//		cin >> s[i];
//	}
//	map<pair<char, char>, int> M;
//	M[{'N', 'N'}] = 0;
//	M[{'S', 'S'}] = 0;
//	M[{'E', 'E'}] = 0;
//	M[{'W', 'W'}] = 0;
//	M[{'N', 'E'}] = 1;
//	M[{'E', 'S'}] = 1;
//	M[{'S', 'W'}] = 1;
//	M[{'W', 'N'}] = 1;
//	M[{'N', 'S'}] = 2;
//	M[{'E', 'W'}] = 2;
//	M[{'S', 'N'}] = 2;
//	M[{'W', 'E'}] = 2;
//	M[{'N', 'W'}] = 3;
//	M[{'E', 'N'}] = 3;
//	M[{'S', 'E'}] = 3;
//	M[{'W', 'S'}] = 3;
//	if(m == 1) {
//		bool w = 1;
//		int S = 0;
//		for(int i = 0; i < n - 1; i++) {
//			if(s[0][i] == 'X') {
//				w = 0;
//				break;
//			}
//			if(s[0][i] != 'E') {
//				S += M[{s[0][i], 'E'}];
//			}
//		}
//		cout << (w ? S : -1) << '\n';
//	}
//	return 0;
//}
#include <bits/stdc++.h>
#define P pair<int, pair<int, int>>
#define s second
#define f first
using namespace std;
using ll = long long;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
char dz[4] = {'E', 'W', 'S', 'N'};
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	char s[n + 1][m + 1];
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> s[i][j];
		}
	}
	map<pair<char, char>, int> M;
	M[{'N', 'N'}] = 0;
	M[{'S', 'S'}] = 0;
	M[{'E', 'E'}] = 0;
	M[{'W', 'W'}] = 0;
	M[{'N', 'E'}] = 1;
	M[{'E', 'S'}] = 1;
	M[{'S', 'W'}] = 1;
	M[{'W', 'N'}] = 1;
	M[{'N', 'S'}] = 2;
	M[{'E', 'W'}] = 2;
	M[{'S', 'N'}] = 2;
	M[{'W', 'E'}] = 2;
	M[{'N', 'W'}] = 3;
	M[{'E', 'N'}] = 3;
	M[{'S', 'E'}] = 3;
	M[{'W', 'S'}] = 3;
	priority_queue<P, vector<P>, greater<P>> pq;
	pq.push({0, {1, 1}});
	vector<vector<int>> dis(n + 1, vector<int> (m + 1, 1e9));
	dis[1][1] = 0;
	while(!pq.empty()) {
		int z = pq.top().f;
		int x = pq.top().s.f;
		int y = pq.top().s.s;
		pq.pop();
		if(z != dis[x][y] || s[x][y] == 'X') continue;
		for(int i = 0; i < 4; i++) {
			int X = x + dx[i];
			int Y = y + dy[i];
			int Z = M[{s[x][y], dz[i]}];
			if(X > 0 && Y > 0 && X <= n && Y <= m && dis[X][Y] > dis[x][y] + Z) {
				dis[X][Y] = dis[x][y] + Z;
				pq.push({dis[X][Y], {X, Y}});
			}
		}
	}
	cout << (dis[n][m] == 1e9 ? -1 : dis[n][m]) << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 4 ms 592 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 5 ms 604 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 52 ms 1972 KB Output is correct
40 Correct 51 ms 2392 KB Output is correct
41 Correct 3 ms 1712 KB Output is correct
42 Correct 53 ms 1968 KB Output is correct
43 Correct 77 ms 5068 KB Output is correct
44 Correct 3 ms 1880 KB Output is correct