답안 #715573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715573 2023-03-27T08:41:11 Z Iliya_ Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1169 ms 877164 KB
// IN THE NAME OF GOD
#include<bits/stdc++.h>
#define endl '\n'
#define file_reading freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define flush cout.flush();
using namespace std;
typedef long long ll;
typedef long double dll;
typedef unsigned long long ull;
 
const int N = 4e3+5; 
int dat[N][N], mark[N][N], ans, having, must; 
vector<pair<int,int>> gone, later; 
int n,m;

void dfs(int x, int y){
	mark[x][y] = 1; 
	having++;
	if (x > 1 && dat[x][y] == dat[x-1][y] && !mark[x-1][y]) dfs(x-1,y);
	if (x < n && dat[x][y] == dat[x+1][y] && !mark[x+1][y]) dfs(x+1,y);
	if (y > 1 && dat[x][y] == dat[x][y-1] && !mark[x][y-1]) dfs(x,y-1);
	if (y < m && dat[x][y] == dat[x][y+1] && !mark[x][y+1]) dfs(x,y+1);
	if (x > 1 && dat[x][y] != dat[x-1][y] && !mark[x-1][y] && dat[x][y] + dat[x-1][y] == 3) later.push_back({x-1,y});
	if (x < n && dat[x][y] != dat[x+1][y] && !mark[x+1][y] && dat[x][y] + dat[x+1][y] == 3) later.push_back({x+1,y});
	if (y > 1 && dat[x][y] != dat[x][y-1] && !mark[x][y-1] && dat[x][y] + dat[x][y-1] == 3) later.push_back({x,y-1});
	if (y < m && dat[x][y] != dat[x][y+1] && !mark[x][y+1] && dat[x][y] + dat[x][y+1] == 3) later.push_back({x,y+1});
}
 
void solve(){  
	cin >> n >> m; 
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			char g; cin >> g; 
			if (g == '.') dat[i][j] = 0; 
			else if (g == 'R') dat[i][j] = 1, must++; 
			else dat[i][j] = 2, must++; 
		}
	}
	if (must == 0){cout << 0 << endl; return;}
	ans = 1; 
	dfs(n,m); 
	while(having != must){
		ans++; 
		gone.clear(); 
		for(pair<int,int> cur : later) gone.push_back(cur); 
		later.clear();
		for(pair<int,int> cur : gone) if (!mark[cur.first][cur.second]) dfs(cur.first,cur.second); 
		
	}
	cout << ans << endl; 
}
 
int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t; t=1; //cin >> t;
	while(t--){solve();}
}

# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 6580 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 10 ms 6612 KB Output is correct
5 Correct 4 ms 3284 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 4 ms 2772 KB Output is correct
11 Correct 4 ms 2772 KB Output is correct
12 Correct 9 ms 3540 KB Output is correct
13 Correct 4 ms 3284 KB Output is correct
14 Correct 4 ms 3284 KB Output is correct
15 Correct 21 ms 6304 KB Output is correct
16 Correct 25 ms 6488 KB Output is correct
17 Correct 14 ms 6108 KB Output is correct
18 Correct 13 ms 6612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 31612 KB Output is correct
2 Correct 80 ms 20000 KB Output is correct
3 Correct 415 ms 105240 KB Output is correct
4 Correct 114 ms 44168 KB Output is correct
5 Correct 247 ms 80104 KB Output is correct
6 Correct 872 ms 183100 KB Output is correct
7 Correct 19 ms 32980 KB Output is correct
8 Correct 18 ms 31656 KB Output is correct
9 Correct 3 ms 1236 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 20 ms 32340 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 70 ms 19924 KB Output is correct
14 Correct 39 ms 13260 KB Output is correct
15 Correct 36 ms 16216 KB Output is correct
16 Correct 32 ms 7812 KB Output is correct
17 Correct 169 ms 41300 KB Output is correct
18 Correct 167 ms 47820 KB Output is correct
19 Correct 130 ms 44104 KB Output is correct
20 Correct 107 ms 35996 KB Output is correct
21 Correct 270 ms 80340 KB Output is correct
22 Correct 269 ms 80120 KB Output is correct
23 Correct 371 ms 66076 KB Output is correct
24 Correct 252 ms 77040 KB Output is correct
25 Correct 601 ms 126188 KB Output is correct
26 Correct 1169 ms 877164 KB Output is correct
27 Correct 814 ms 322560 KB Output is correct
28 Correct 832 ms 182948 KB Output is correct
29 Correct 833 ms 177456 KB Output is correct
30 Correct 837 ms 223036 KB Output is correct
31 Correct 815 ms 102956 KB Output is correct
32 Correct 881 ms 389056 KB Output is correct