답안 #465180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465180 2021-08-15T09:59:11 Z Elias Awesome Arrowland Adventure (eJOI19_adventure) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

vector<vector<pair<int, int>>> adj;
vector<bool> visited;

int dijkstra(int s, int e)
{
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	pq.push({0, s});
	visited[0] = true;
	while (pq.size())
	{
		auto [dist, x] = pq.top();
		pq.pop();
		visited[x] = true;
		if (x == e)
			return dist;
		for (auto [d, c] : adj[x])
		{
			if (visited[c])
				continue;
			pq.push({d + dist, c});
		}
	}

	return -1;
}

signed main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> m >> n;

	adj = vector<vector<pair<int, int>>>(n * m);
	visited = vector<bool>(n * m);

	string row;

	for (int y = 0; y < m; y++)
	{
		cin >> row;
		for (int x = 0; x < n; x++)
		{
			int dir = row[x];
			if (dir == 'X')
				continue;
			if (dir == 'N')
				dir = 0;
			if (dir == 'E')
				dir = 3;
			if (dir == 'S')
				dir = 2;
			if (dir == 'W')
				dir = 1;

			for (auto [pX, pY] : vector<pair<int, int>>{{0, -1}, {1, 0}, {0, 1}, {-1, 0}})
			{
				int dist = dir;
				dir = (dir + 1) % 4;

				int newX = x + pX;
				int newY = y + pY;
				if (newX < 0 || newX >= n || newY < 0 || newY >= m)
					continue;

				adj[x + y * n].push_back({dist, newX + newY * n});
			}
		}
	}

	cout << dijkstra(0, (n - 1) * (m - 1));
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -