답안 #684680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684680 2023-01-22T10:20:14 Z peijar Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
216 ms 14904 KB
#include <bits/stdc++.h>
#define MAXN 507
using namespace std;
int ind[MAXN][MAXN],dist[MAXN][MAXN],dx[4]={0,1,0,-1},dy[4]={-1,0,1,0},n,m;
void dijkstra()
{
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) dist[i][j]=-1;
	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(ind[y][x]==-1) continue;
		for(int i=0;i<4;i++) pq.push(make_pair(c+i,make_pair(x+dx[(ind[y][x]+i)%4],y+dy[(ind[y][x]+i)%4])));
	}
}
int 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') ind[i][j]=0;
		if(c=='E') ind[i][j]=1;
		if(c=='S') ind[i][j]=2;
		if(c=='W') ind[i][j]=3;
		if(c=='X') ind[i][j]=-1;
	}
	dijkstra();
	cout<<dist[n-1][m-1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 308 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 11 ms 452 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 13 ms 704 KB Output is correct
38 Correct 4 ms 1364 KB Output is correct
39 Correct 127 ms 2644 KB Output is correct
40 Correct 123 ms 2560 KB Output is correct
41 Correct 18 ms 2528 KB Output is correct
42 Correct 129 ms 2644 KB Output is correct
43 Correct 216 ms 14904 KB Output is correct
44 Correct 17 ms 2516 KB Output is correct