답안 #697451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697451 2023-02-09T21:22:48 Z aklo Awesome Arrowland Adventure (eJOI19_adventure) C++14
100 / 100
91 ms 17308 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 505;
int n, m, b;
char a[N][N];
set <pair <int, pair <int,int> > > s;
char slj[10] = {'N', 'E', 'S', 'W', 'N', 'E', 'S', 'W'};

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
	
	cin >> n >> m;
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
 	}
 	
 	s.insert({0,{0,0}});
 	int dist[N][N];
 	memset(dist, -1, sizeof(dist));
 	while (s.size() > 0){
 		//cout<<"\n";
 		//cout<<s.begin()->first<<" "<<s.begin()->second.first<<" "<<s.begin()->second.second<<"\n";
 		int x = s.begin()->second.first;
 		int y = s.begin()->second.second;
 		b=s.begin()->first;
 		s.erase(s.begin());
 		if(dist[x][y]!=-1) continue;
 		dist[x][y] = b;
 		if(a[x][y]=='X') continue;
 		//cout<<x<<" "<<y<<" "<<dist[x][y]<<"\n";
 		for (int i = 0; i < 4; i++){
 			int nx = x + dx[i];
 			int ny = y + dy[i];
 			//if(x==0 && y==0) cout<<nx<<" a "<<ny<<" "<<dist[nx][ny]<<"\n";
 			if (nx >= n or ny >= m) continue;
 			if (nx < 0 or ny < 0) continue;
 			if (dist[nx][ny] != -1) continue;
			
			int ud = 0;
			bool p = 0;
			for (int j = 0; j < 4; j++){
				if (p) break;
				if (a[x][y] == slj[j]){
					for (int k = j; k < 8; k++){
						if (slj[k] == slj[i]) p = 1;
						if (p) break;
						ud++;
					}
				}	
		 	}
		 	//cout<<dist[x][y]+ud<<" "<<nx<<" "<<ny<<"\n";
		 	
		 	s.insert({dist[x][y] + ud,{nx,ny}});
		}
	}
	
	cout << dist[n-1][m-1];
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1304 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1308 KB Output is correct
14 Correct 1 ms 1304 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1300 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 1 ms 1304 KB Output is correct
4 Correct 1 ms 1304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1308 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1308 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 1 ms 1304 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1308 KB Output is correct
14 Correct 1 ms 1304 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1236 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1300 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1312 KB Output is correct
23 Correct 1 ms 1304 KB Output is correct
24 Correct 1 ms 1304 KB Output is correct
25 Correct 1 ms 1308 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1300 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1308 KB Output is correct
32 Correct 1 ms 1364 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 7 ms 1364 KB Output is correct
36 Correct 1 ms 1308 KB Output is correct
37 Correct 9 ms 1316 KB Output is correct
38 Correct 3 ms 1364 KB Output is correct
39 Correct 80 ms 1900 KB Output is correct
40 Correct 78 ms 1840 KB Output is correct
41 Correct 14 ms 1748 KB Output is correct
42 Correct 91 ms 1988 KB Output is correct
43 Correct 84 ms 17308 KB Output is correct
44 Correct 15 ms 1748 KB Output is correct