Submission #1090721

# Submission time Handle Problem Language Result Execution time Memory
1090721 2024-09-18T15:54:32 Z Taxiradio Zoo (COCI19_zoo) C++17
0 / 110
1408 ms 524288 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int g[1004][1004];
queue<array<int , 2>> t , b;
int c = 0;
vector<array<int , 2>> l = {{1 , 0},{-1 , 0},{0 , -1},{0 , 1}};
void T(){
	while(!t.empty()){
		auto [h , j] = t.front();
		t.pop();
		for(auto[x , y] : l){
			if(g[h-x][j-y] == 1){
				t.push({h-x , j-y});
				g[h][j] = 0;
			}
			if(g[h-x][j-y] == 2){
				b.push({h-x , j-y});
				g[h][j] = 0;
			}
		}
	}
} 

void B(){
	while(!b.empty()){
		auto [h , j] = b.front();
		b.pop();
		for(auto[x , y] : l){
			if(g[h-x][j-y] == 1){
				t.push({h-x , j-y});
				g[h][j] = 0;
			}
			if(g[h-x][j-y] == 2){
				b.push({h-x , j-y});
				g[h][j] = 0;
			}
		}
	}
} 

int main() {
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int i2 = 1; i2 <=m; i2++){
			char y; cin >> y;
			if(y == 'T'){
				g[i][i2] = 1;
				c++;
			}
			if(y == 'B'){
				g[i][i2] = 2;
				c++;
			}
		}	
	}
	int ans = 0;
	if(g[1][1] == 1){
		t.push({1,  1});
	}else if(g[1][1] == 2){
		b.push({1 , 1});
		ans++;
		B();
	}

	while(1){
		if(t.empty() && b.empty()){
			cout << ans << endl;
			return 0;
		}
		ans++;
		T();
		if(t.empty() && b.empty()){
			cout << ans << endl;
			return 0;
		}
		ans++;
		B();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 23 ms 3932 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Runtime error 1408 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 23 ms 3932 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Runtime error 1408 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -