Submission #1062363

#TimeUsernameProblemLanguageResultExecution timeMemory
1062363danielzhuTracks in the Snow (BOI13_tracks)C++17
93.44 / 100
2076 ms73560 KiB
#include <bits/stdc++.h>
using namespace std;
int H, W;
char grid[4001][4001];
vector<pair<int,int>> dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

void bfs(set<pair<int,int>> &from, set<pair<int,int>> &to, char cc){
	while(!from.empty()){
			auto temp = from.begin();
			from.erase(from.begin());
			//from.erase({temp->first, temp->second});
			int x = temp->first, y = temp->second;
			for(auto [dx, dy] : dir){
				if(x+dx > -1 && x+dx < H && y+dy > -1 && y+dy < W && grid[x+dx][y+dy] != '.'){
					if(grid[x+dx][y+dy] != cc) to.insert({x+dx, y+dy});
					else from.insert({x+dx, y+dy});
					grid[x+dx][y+dy] = '.';
				}
			}
	}
}

int main(){
	cin>>H>>W;
	for(int i = 0; i < H; i++){
		string s; cin>>s;
		for(int j = 0; j < W; j++){
			grid[i][j] = s[j];
		}
	}
	int x = 0, y = 0, ans = 0;
	char cc = grid[0][0];
	set<pair<int,int>> F, R;
	if(cc == 'F') F.insert({0,0});
	else R.insert({0,0});
	grid[0][0] = '.';
	while(true){
		if(cc == 'F' && F.empty()) break;
		if(cc == 'R' && R.empty()) break;
		if(cc == 'F')
			bfs(F, R, cc);
		else if(cc == 'R')
			bfs(R, F, cc);
		ans++;
		if(cc == 'F') cc = 'R';
		else if(cc == 'R') cc = 'F';
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:31:6: warning: unused variable 'x' [-Wunused-variable]
   31 |  int x = 0, y = 0, ans = 0;
      |      ^
tracks.cpp:31:13: warning: unused variable 'y' [-Wunused-variable]
   31 |  int x = 0, y = 0, ans = 0;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...