답안 #876656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876656 2023-11-22T07:28:51 Z vjudge1 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
341 ms 90784 KB
#include <iostream>
#include <vector>
#include <queue>

#define endl '\n'
#define pb emplace_back
#define front back
#define pop pop_back
#define push emplace_back
#define fr first
#define sc second
#define mp make_pair

using namespace std;

typedef pair<int, int> pi;

int n, h, w;
const int MAXN = 4010;

string mat[4010];

vector<pi> q[2];

bool used[MAXN][MAXN];


int x[4] = {1, 0, -1, 0};
int y[4] = {0, -1, 0, 1};

int main(){
	ios::sync_with_stdio(0);cin.tie(0);

	cin >> h >> w;

	for(int i=0; i<h; i++) cin >> mat[i];

	int p, cnt = 0;
	used[0][0] = 1;

	p = (mat[0][0] == 'F');	

	q[p].pb(mp(0, 0));
	while(!q[0].empty() || !q[1].empty()){
		
		while(!q[p].empty()){
			pi v = q[p].front();
			q[p].pop();

			
			for(int i=0; i<4; i++){
				
				pi u = mp(v.fr+x[i], v.sc+y[i]);

				
				if(u.fr == -1 || u.sc == -1 || u.fr == h || u.sc == w || mat[u.fr][u.sc] == '.') continue;

				if(used[u.fr][u.sc]) continue;

				bool tp = (mat[u.fr][u.sc] == 'F');
				q[tp].push(u);
				used[u.fr][u.sc] = 1;
			
			}
		}

		p ^= 1;
		cnt++;
	}

	cout << cnt << endl;

	return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2940 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 4 ms 3080 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 3 ms 1884 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 2 ms 1628 KB Output is correct
15 Correct 5 ms 2652 KB Output is correct
16 Correct 6 ms 2908 KB Output is correct
17 Correct 5 ms 2904 KB Output is correct
18 Correct 4 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15452 KB Output is correct
2 Correct 20 ms 7180 KB Output is correct
3 Correct 120 ms 33952 KB Output is correct
4 Correct 30 ms 11868 KB Output is correct
5 Correct 89 ms 22068 KB Output is correct
6 Correct 341 ms 59544 KB Output is correct
7 Correct 8 ms 16220 KB Output is correct
8 Correct 6 ms 15452 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 6 ms 15964 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 21 ms 7104 KB Output is correct
14 Correct 12 ms 4956 KB Output is correct
15 Correct 9 ms 5468 KB Output is correct
16 Correct 10 ms 2652 KB Output is correct
17 Correct 55 ms 12636 KB Output is correct
18 Correct 42 ms 12632 KB Output is correct
19 Correct 30 ms 11868 KB Output is correct
20 Correct 30 ms 11096 KB Output is correct
21 Correct 72 ms 22780 KB Output is correct
22 Correct 88 ms 21848 KB Output is correct
23 Correct 116 ms 18856 KB Output is correct
24 Correct 80 ms 22364 KB Output is correct
25 Correct 246 ms 33932 KB Output is correct
26 Correct 226 ms 90784 KB Output is correct
27 Correct 295 ms 77468 KB Output is correct
28 Correct 340 ms 59796 KB Output is correct
29 Correct 334 ms 53876 KB Output is correct
30 Correct 321 ms 58256 KB Output is correct
31 Correct 221 ms 25172 KB Output is correct
32 Correct 266 ms 69660 KB Output is correct