답안 #229216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229216 2020-05-03T21:02:12 Z VEGAnn Zoo (COCI19_zoo) C++14
110 / 110
67 ms 6328 KB
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ft first
#define sd second
#define pii pair<int, int>
#define sz(x) ((int)x.size())
using namespace std;
const int N = 1010;
typedef long long ll;
queue<pii> q[2];
char c[N][N];
int n, m, mrk[N][N], tt = 0, st, ans = 0, step[4][2];
string pt = "BT";

void rec(int x, int y){
	if (c[x][y] == pt[st ^ 1] || c[x][y] == '*' || mrk[x][y] == tt)
		return;
	mrk[x][y] = tt;
	c[x][y] = 'N';
	
	if (x > 0) rec(x - 1, y);
	if (y > 0) rec(x, y - 1);
	if (y < m - 1) rec(x, y + 1);
	if (x < n - 1) rec(x + 1, y);
}

int main(){
	
	ios_base::sync_with_stdio(0); cin.tie(0);
	
//	freopen("in.txt","r",stdin);
	
	step[0][0] = 1; step[0][1] = 0;
	step[1][0] = -1; step[1][1] = 0;
	step[2][0] = 0; step[2][1] = 1;
	step[3][0] = 0; step[3][1] = -1;
	
	cin >> n >> m;
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> c[i][j];
	
	st = pt.find(c[0][0]);
		
	q[st].push(MP(0, 0));
	mrk[0][0] = 1;
	
	for (;; st ^= 1){
		if (!sz(q[st])) break;
		
		ans++;
		
		while (sz(q[st])){
			pii cr = q[st].front(); q[st].pop();
			int x = cr.ft, y = cr.sd;
			
//			cerr << x << " " << y << '\n';
			
			for (int it = 0; it < 4; it++){
				int cx = x + step[it][0];
				int cy = y + step[it][1];
				
				if (cx >= 0 && cy >= 0 && cx < n && cy < m && 
					!mrk[cx][cy] && c[cx][cy] != '*'){
						mrk[cx][cy] = 1;
						q[pt.find(c[cx][cy])].push(MP(cx, cy));
					}
			}
		}
	}
	
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 896 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 896 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 5 ms 896 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 896 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 896 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 5 ms 896 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
16 Correct 26 ms 6144 KB Output is correct
17 Correct 26 ms 6144 KB Output is correct
18 Correct 25 ms 6272 KB Output is correct
19 Correct 27 ms 6144 KB Output is correct
20 Correct 25 ms 6272 KB Output is correct
21 Correct 63 ms 6016 KB Output is correct
22 Correct 62 ms 6016 KB Output is correct
23 Correct 62 ms 6016 KB Output is correct
24 Correct 66 ms 6328 KB Output is correct
25 Correct 67 ms 6272 KB Output is correct
26 Correct 65 ms 6016 KB Output is correct
27 Correct 62 ms 6008 KB Output is correct
28 Correct 61 ms 6016 KB Output is correct
29 Correct 67 ms 6272 KB Output is correct
30 Correct 65 ms 6144 KB Output is correct