답안 #650616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650616 2022-10-14T09:39:15 Z Kenpar Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
185 ms 14252 KB
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 1e5+1;

vector<vector<int>> rotation(200, vector<int>(4));
vector<vector<int>> moves = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
void solve(){
	rotation['N'][0] = 1;
	rotation['N'][1] = 2;
	rotation['N'][2] = 3;
	rotation['N'][3] = 0;

	rotation['E'][0] = 0;
	rotation['E'][1] = 1;
	rotation['E'][2] = 2;
	rotation['E'][3] = 3;

	rotation['S'][0] = 3;
	rotation['S'][1] = 0;
	rotation['S'][2] = 1;
	rotation['S'][3] = 2;

	rotation['W'][0] = 2;
	rotation['W'][1] = 3;
	rotation['W'][2] = 0;
	rotation['W'][3] = 1;

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

	vector<vector<int>> dp(n, vector<int>(m, -1));
	vector<vector<char>> arr(n, vector<char>(m));

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin>>arr[i][j];
		}
	}

	priority_queue<pair<int, pair<int,int>>, vector<pair<int, pair<int,int>>>, greater<pair<int, pair<int,int>>>> pq;

	pq.push({0,{0,0}});

	while(!pq.empty()){
		pair<int, pair<int,int>> top = pq.top();
		pq.pop();

		if(top.second.first < 0 || top.second.first >= n) continue;
		if(top.second.second < 0 || top.second.second >= m) continue;

		if(dp[top.second.first][top.second.second] != -1) continue;

		dp[top.second.first][top.second.second] = top.first;

		//cout<<top.second.first<<" "<<top.second.second<<" : "<<top.first<<endl;
		if(arr[top.second.first][top.second.second] == 'X') continue;
		for(int i = 0; i < 4; i++){
			//cout<<" i: "<<i<<" "<<arr[top.second.first][top.second.second]<<" "<<rotation[arr[top.second.first][top.second.second]][i]<<endl;
			pq.push({top.first + rotation[arr[top.second.first][top.second.second]][i],
				{top.second.first + moves[i][0], top.second.second + moves[i][1]}});
		}
	}

	cout<<dp[n-1][m-1];
}


int main()
{
	cin.tie(NULL);
	ios::sync_with_stdio(NULL);
	int t = 1;

	//cin >> t;

	while(t--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 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 328 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 336 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 268 KB Output is correct
20 Correct 1 ms 340 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 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 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 328 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 336 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 268 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 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 328 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 13 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 12 ms 468 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 125 ms 1896 KB Output is correct
40 Correct 129 ms 1880 KB Output is correct
41 Correct 6 ms 1760 KB Output is correct
42 Correct 135 ms 2044 KB Output is correct
43 Correct 185 ms 14252 KB Output is correct
44 Correct 4 ms 1748 KB Output is correct