답안 #876655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876655 2023-11-22T07:27:54 Z vjudge1 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
568 ms 90960 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 10 ms 2904 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 6 ms 3044 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 1 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 1624 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 4 ms 1884 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 3 ms 1628 KB Output is correct
15 Correct 9 ms 2908 KB Output is correct
16 Correct 10 ms 3132 KB Output is correct
17 Correct 8 ms 2908 KB Output is correct
18 Correct 6 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 15452 KB Output is correct
2 Correct 41 ms 7840 KB Output is correct
3 Correct 326 ms 46164 KB Output is correct
4 Correct 79 ms 14856 KB Output is correct
5 Correct 196 ms 23628 KB Output is correct
6 Correct 562 ms 72028 KB Output is correct
7 Correct 7 ms 16220 KB Output is correct
8 Correct 7 ms 15452 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 7 ms 15708 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 44 ms 8284 KB Output is correct
14 Correct 25 ms 5720 KB Output is correct
15 Correct 23 ms 6224 KB Output is correct
16 Correct 18 ms 2904 KB Output is correct
17 Correct 109 ms 15912 KB Output is correct
18 Correct 95 ms 16208 KB Output is correct
19 Correct 79 ms 15040 KB Output is correct
20 Correct 73 ms 14052 KB Output is correct
21 Correct 188 ms 24268 KB Output is correct
22 Correct 203 ms 23636 KB Output is correct
23 Correct 206 ms 19800 KB Output is correct
24 Correct 203 ms 24524 KB Output is correct
25 Correct 445 ms 46164 KB Output is correct
26 Correct 386 ms 90960 KB Output is correct
27 Correct 523 ms 89172 KB Output is correct
28 Correct 568 ms 71324 KB Output is correct
29 Correct 561 ms 63456 KB Output is correct
30 Correct 542 ms 70300 KB Output is correct
31 Correct 368 ms 26312 KB Output is correct
32 Correct 472 ms 80804 KB Output is correct