Submission #288085

# Submission time Handle Problem Language Result Execution time Memory
288085 2020-09-01T08:38:23 Z MKutayBozkurt Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
236 ms 27596 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

#define int long long

const int inf = 1e18;
int n, m;
vector<vector<char>> a;
int sp() {
	priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
	vector<vector<int>> ans(n, vector<int>(m, -1));
	pq.push({0, {0, 0}});
	while (pq.size()) {
		int z = pq.top().first;
		int x = pq.top().second.first;
		int y = pq.top().second.second;
		pq.pop();
		if (x < 0 || y < 0 || x >= n || y >= m || ans[x][y] != -1) continue;
		ans[x][y] = z;
		if (a[x][y] == 'E') {
			pq.push({z, {x, y + 1}});
			pq.push({z + 1, {x + 1, y}});
			pq.push({z + 2, {x, y - 1}});
			pq.push({z + 3, {x - 1, y}});
		} else if (a[x][y] == 'S') {
			pq.push({z, {x + 1, y}});
			pq.push({z + 1, {x, y - 1}});
			pq.push({z + 2, {x - 1, y}});
			pq.push({z + 3, {x, y + 1}});
		} else if (a[x][y] == 'W') {
			pq.push({z, {x, y - 1}});
			pq.push({z + 1, {x - 1, y}});
			pq.push({z + 2, {x, y + 1}});
			pq.push({z + 3, {x + 1, y}});
		} else if (a[x][y] == 'N') {
			pq.push({z, {x - 1, y}});
			pq.push({z + 1, {x, y + 1}});
			pq.push({z + 2, {x + 1, y}});
			pq.push({z + 3, {x, y - 1}});
		}
	}
	return ans[n - 1][m - 1];
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*
	her 4 yere bir cost ile gidiyon
	*/
	cin >> n >> m;
	a = vector<vector<char>>(n, vector<char>(m)); cin >> a;
	cout << sp() << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 12 ms 640 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 14 ms 640 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 147 ms 3192 KB Output is correct
40 Correct 146 ms 3068 KB Output is correct
41 Correct 5 ms 2816 KB Output is correct
42 Correct 147 ms 3288 KB Output is correct
43 Correct 236 ms 27596 KB Output is correct
44 Correct 5 ms 2816 KB Output is correct