Submission #1062359

# Submission time Handle Problem Language Result Execution time Memory
1062359 2024-08-17T04:00:48 Z danielzhu Tracks in the Snow (BOI13_tracks) C++17
100 / 100
556 ms 26084 KB
#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(queue<pair<int,int>> &from, queue<pair<int,int>> &to, char cc){
	while(!from.empty()){
			auto temp = from.front();
			from.pop();
			//grid[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.push({x+dx, y+dy});
					else from.push({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];
	queue<pair<int,int>> F, R;
	if(cc == 'F') F.push({0,0});
	else R.push({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

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 time Memory Grader output
1 Correct 10 ms 2908 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2664 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 9 ms 2940 KB Output is correct
16 Correct 9 ms 2652 KB Output is correct
17 Correct 6 ms 2648 KB Output is correct
18 Correct 6 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 45 ms 6768 KB Output is correct
3 Correct 334 ms 16216 KB Output is correct
4 Correct 69 ms 8812 KB Output is correct
5 Correct 177 ms 12884 KB Output is correct
6 Correct 530 ms 26084 KB Output is correct
7 Correct 3 ms 15964 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 3 ms 15708 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 37 ms 6764 KB Output is correct
14 Correct 22 ms 4700 KB Output is correct
15 Correct 20 ms 4712 KB Output is correct
16 Correct 17 ms 2648 KB Output is correct
17 Correct 95 ms 8804 KB Output is correct
18 Correct 74 ms 8556 KB Output is correct
19 Correct 67 ms 8784 KB Output is correct
20 Correct 64 ms 8800 KB Output is correct
21 Correct 173 ms 12900 KB Output is correct
22 Correct 177 ms 12900 KB Output is correct
23 Correct 183 ms 10848 KB Output is correct
24 Correct 184 ms 12884 KB Output is correct
25 Correct 302 ms 15952 KB Output is correct
26 Correct 297 ms 15188 KB Output is correct
27 Correct 417 ms 17744 KB Output is correct
28 Correct 533 ms 26064 KB Output is correct
29 Correct 556 ms 24528 KB Output is correct
30 Correct 504 ms 23532 KB Output is correct
31 Correct 407 ms 15440 KB Output is correct
32 Correct 386 ms 24912 KB Output is correct