Submission #1062357

# Submission time Handle Problem Language Result Execution time Memory
1062357 2024-08-17T03:54:19 Z danielzhu Tracks in the Snow (BOI13_tracks) C++17
31.25 / 100
2000 ms 1048576 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});
				}
			}
	}
}

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});
	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:30:6: warning: unused variable 'x' [-Wunused-variable]
   30 |  int x = 0, y = 0, ans = 0;
      |      ^
tracks.cpp:30:13: warning: unused variable 'y' [-Wunused-variable]
   30 |  int x = 0, y = 0, ans = 0;
      |             ^
# Verdict Execution time Memory Grader output
1 Execution timed out 2071 ms 984076 KB Time limit exceeded
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 2039 ms 308836 KB Time limit exceeded
4 Execution timed out 2093 ms 942524 KB Time limit exceeded
5 Execution timed out 2115 ms 1008428 KB Time limit exceeded
6 Correct 1 ms 344 KB Output is correct
7 Execution timed out 2053 ms 308964 KB Time limit exceeded
8 Execution timed out 2088 ms 993336 KB Time limit exceeded
9 Correct 26 ms 3160 KB Output is correct
10 Execution timed out 2041 ms 805880 KB Time limit exceeded
11 Execution timed out 2096 ms 878132 KB Time limit exceeded
12 Execution timed out 2057 ms 1048576 KB Time limit exceeded
13 Execution timed out 2112 ms 1011268 KB Time limit exceeded
14 Execution timed out 2104 ms 1014456 KB Time limit exceeded
15 Execution timed out 2116 ms 1048576 KB Time limit exceeded
16 Execution timed out 2094 ms 1002736 KB Time limit exceeded
17 Execution timed out 2076 ms 868652 KB Time limit exceeded
18 Execution timed out 2082 ms 924180 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15192 KB Output is correct
2 Execution timed out 2124 ms 763936 KB Time limit exceeded
3 Execution timed out 2070 ms 462672 KB Time limit exceeded
4 Execution timed out 2049 ms 270300 KB Time limit exceeded
5 Correct 197 ms 17812 KB Output is correct
6 Execution timed out 2065 ms 865484 KB Time limit exceeded
7 Correct 3 ms 15960 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Execution timed out 2129 ms 722580 KB Time limit exceeded
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 Execution timed out 2125 ms 746304 KB Time limit exceeded
14 Execution timed out 2068 ms 931608 KB Time limit exceeded
15 Correct 20 ms 5464 KB Output is correct
16 Execution timed out 2101 ms 746724 KB Time limit exceeded
17 Execution timed out 2071 ms 468748 KB Time limit exceeded
18 Correct 72 ms 11088 KB Output is correct
19 Execution timed out 2114 ms 270228 KB Time limit exceeded
20 Execution timed out 2033 ms 221284 KB Time limit exceeded
21 Execution timed out 2084 ms 248384 KB Time limit exceeded
22 Correct 178 ms 17488 KB Output is correct
23 Execution timed out 2043 ms 296544 KB Time limit exceeded
24 Correct 177 ms 17512 KB Output is correct
25 Correct 298 ms 24180 KB Output is correct
26 Execution timed out 2090 ms 807796 KB Time limit exceeded
27 Execution timed out 2045 ms 751236 KB Time limit exceeded
28 Execution timed out 2083 ms 871996 KB Time limit exceeded
29 Execution timed out 2060 ms 807896 KB Time limit exceeded
30 Execution timed out 2074 ms 974600 KB Time limit exceeded
31 Execution timed out 2054 ms 964296 KB Time limit exceeded
32 Execution timed out 2054 ms 1048576 KB Time limit exceeded