답안 #640234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640234 2022-09-14T03:59:33 Z maks007 Awesome Arrowland Adventure (eJOI19_adventure) C++14
100 / 100
92 ms 8904 KB
#include "bits/stdc++.h"

#define int long long

int it[] = {0,0,1,-1};
int jt[] = {1,-1,0,0};

int f(char ch, char c) {
	if(ch == 'S') {
		if(c == 'E') return 3;
		if(c == 'S') return 0;
		if(c == 'W') return 1;
		if(c == 'N') return 2;
	}
	if(ch == 'W') {
		if(c == 'E') return 2;
		if(c == 'S') return 3;
		if(c == 'W') return 0;
		if(c == 'N') return 1;
	}
	if(ch == 'E') {
		if(c == 'E') return 0;
		if(c == 'S') return 1;
		if(c == 'W') return 2;
		if(c == 'N') return 3;
	}
	if(ch == 'N') {	
		if(c == 'E') return 1;
		if(c == 'S') return 2;
		if(c == 'W') return 3;
		if(c == 'N') return 0;
	}
}

signed main () {
	int n, m;
	scanf("%lld%lld", &n, &m);
	char a[n][m];
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) std::cin >> a[i][j];
	}
	std::priority_queue <std::pair <int,std::pair <int,int> >  > q;
	int d[n][m];
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) d[i][j] = (int)1e16;
	}
	q.push({0, {n-1, m-1}});
	d[n-1][m-1] = 0;
	while(!q.empty()) {
		std::pair <int,int> v = q.top().second;
		q.pop();
		// printf("%lld %lld\n", v.first, v.second);
		for(int i = 0; i < 4; i ++) {
			int ni = v.first + it[i];
			int nj = v.second + jt[i];
			if(ni >= n || nj >= m || ni < 0 || nj < 0) continue;
			if(a[ni][nj] == 'X') continue;
			int cnt = 0;
			if(it[i] == -1) {
				cnt = f(a[ni][nj], 'S');
			}else if(jt[i] == -1) {
				cnt = f(a[ni][nj], 'E');
			}else if(jt[i] == 1) {
				cnt = f(a[ni][nj], 'W');
			}else {
				cnt = f(a[ni][nj], 'N');
			}
			if(d[ni][nj] > d[v.first][v.second] + cnt) {
				d[ni][nj] = d[v.first][v.second] + cnt;
				q.push({-d[ni][nj], {ni, nj}});
			}
		}
	}
	if(d[0][0] == (int)1e16) printf("-1");
	else 
	printf("%lld", d[0][0]);
	return 0;
}

Compilation message

adventure.cpp: In function 'long long int f(char, char)':
adventure.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
   33 | }
      | ^
adventure.cpp: In function 'int main()':
adventure.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%lld%lld", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 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 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 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 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 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 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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
5 Correct 1 ms 296 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 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 300 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 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 296 KB Output is correct
21 Correct 1 ms 304 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 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 296 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 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 6 ms 568 KB Output is correct
38 Correct 10 ms 632 KB Output is correct
39 Correct 62 ms 2764 KB Output is correct
40 Correct 74 ms 2800 KB Output is correct
41 Correct 71 ms 2772 KB Output is correct
42 Correct 62 ms 2732 KB Output is correct
43 Correct 92 ms 8904 KB Output is correct
44 Correct 66 ms 2796 KB Output is correct