답안 #984283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984283 2024-05-16T12:40:07 Z Acanikolic Awesome Arrowland Adventure (eJOI19_adventure) C++14
100 / 100
90 ms 34752 KB
#include <bits/stdc++.h>

#define int long long

#define pb push_back

#define F first

#define S second

const int N = 500 + 10;

const int inf = 2e9;

const int mod = 998244353;

using namespace std;

int dist[N * N],n,m;
vector<pair<int,int>>g[N * N];
char a[N][N];
bool was[N * N];

map<pair<char,char>,int>cost;

int f(int i,int j) {
	return (i - 1) * m + j;
}

char get(int x) {
	int i = x / m + 1;
	int j = x % m;
	return a[i][j];
}

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

	for(int i = 1; i < N * N; i++) dist[i] = inf;
	cost[{'N','N'}] = 0;
	cost[{'N','E'}] = 1;
	cost[{'N','S'}] = 2;
	cost[{'N','W'}] = 3;
	cost[{'E','E'}] = 0;
	cost[{'E','S'}] = 1;
	cost[{'E','W'}] = 2;
	cost[{'E','N'}] = 3;
	cost[{'S','S'}] = 0;
	cost[{'S','W'}] = 1;
	cost[{'S','N'}] = 2;
	cost[{'S','E'}] = 3;
	cost[{'W','W'}] = 0;
	cost[{'W','N'}] = 1;
	cost[{'W','E'}] = 2;
	cost[{'W','S'}] = 3;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> a[i][j];
			if(a[i][j] == 'X') continue;
			if(i >= 2) g[f(i,j)].pb({f(i - 1,j),cost[{a[i][j],'N'}]});
			if(j >= 2) g[f(i,j)].pb({f(i,j - 1),cost[{a[i][j],'W'}]});
			if(i + 1 <= n) g[f(i,j)].pb({f(i + 1,j),cost[{a[i][j],'S'}]});
			if(j + 1 <= m) g[f(i,j)].pb({f(i,j + 1),cost[{a[i][j],'E'}]});
		}
	}
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
	dist[f(1,1)] = 0;
	pq.push({0,f(1,1)});
	while(!pq.empty()) {
		int dst = pq.top().F;
		int u = pq.top().S;
		pq.pop();
		if(was[u] || get(u) == 'X') continue;
		was[u] = true;
		for(auto X : g[u]) {
			if(dist[X.F] > dist[u] + X.S) {
				dist[X.F] = dist[u] + X.S;
				pq.push({dist[X.F],X.F});
			}
		}
	}
	if(dist[f(n,m)] == inf) dist[f(n,m)] = -1;
	cout << dist[f(n,m)];
    return 0;
}

Compilation message

adventure.cpp: In function 'int main()':
adventure.cpp:72:7: warning: unused variable 'dst' [-Wunused-variable]
   72 |   int dst = pq.top().F;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8888 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8888 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8892 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8888 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8892 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 3 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8792 KB Output is correct
28 Correct 2 ms 8796 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 3 ms 8796 KB Output is correct
32 Correct 2 ms 8796 KB Output is correct
33 Correct 2 ms 8796 KB Output is correct
34 Correct 2 ms 8796 KB Output is correct
35 Correct 8 ms 10332 KB Output is correct
36 Correct 2 ms 9052 KB Output is correct
37 Correct 8 ms 10588 KB Output is correct
38 Correct 8 ms 11356 KB Output is correct
39 Correct 71 ms 24660 KB Output is correct
40 Correct 75 ms 24776 KB Output is correct
41 Correct 37 ms 24408 KB Output is correct
42 Correct 71 ms 24812 KB Output is correct
43 Correct 90 ms 34752 KB Output is correct
44 Correct 36 ms 24400 KB Output is correct