Submission #1001250

# Submission time Handle Problem Language Result Execution time Memory
1001250 2024-06-18T17:28:45 Z vjudge3 Tracks in the Snow (BOI13_tracks) C++17
100 / 100
1662 ms 169620 KB
#include <bits/stdc++.h>
using namespace std;

bitset<4005> vis[4005], occ[4005], fox[4005];
vector<pair<int, int>> cur;
int h, w, dep = 1;
const int dr[4] = {0, 1, 0, -1}, dc[4] = {1, 0, -1, 0};

void bfs (int rt, int ct, bool f) {
	queue<pair<int, int>> q;
	q.push({rt, ct});
	while (!q.empty()) {
		auto [r, c] = q.front();
		q.pop();
		for (int k = 0; k < 4; k++) {
			int rv = r + dr[k], cv = c + dc[k];
			if (rv >= 1 && rv <= h && cv >= 1 && cv <= w && !vis[rv][cv] && occ[rv][cv] && fox[rv][cv] == f) {
				q.push({rv, cv});
				cur.push_back({rv, cv});
				vis[rv][cv] = true;
			}
		}
	}
}

int main () {
	cin >> h >> w;
	for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) {
		char ch;
		cin >> ch;
		if (ch != '.') occ[i][j] = true;
		if (ch == 'F') fox[i][j] = true;
	}
	bfs(1, 1, fox[1][1]);
	while (true) {
		vector<pair<int, int>> last;
		last.swap(cur);
		for (auto& [r, c] : last) bfs(r, c, (dep & 1) ^ fox[1][1]);
		last.clear();
		if (cur.empty()) {
			cout << dep << '\n';
			return 0;
		}
		dep++;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3436 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 16 ms 4460 KB Output is correct
5 Correct 5 ms 2648 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 4 ms 3032 KB Output is correct
12 Correct 13 ms 2980 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 6 ms 2572 KB Output is correct
15 Correct 29 ms 2908 KB Output is correct
16 Correct 29 ms 3272 KB Output is correct
17 Correct 20 ms 2984 KB Output is correct
18 Correct 15 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6236 KB Output is correct
2 Correct 104 ms 4956 KB Output is correct
3 Correct 805 ms 6484 KB Output is correct
4 Correct 181 ms 5404 KB Output is correct
5 Correct 589 ms 5968 KB Output is correct
6 Correct 1662 ms 130056 KB Output is correct
7 Correct 4 ms 6236 KB Output is correct
8 Correct 6 ms 5976 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 6 ms 6232 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 98 ms 2212 KB Output is correct
14 Correct 69 ms 4692 KB Output is correct
15 Correct 55 ms 4700 KB Output is correct
16 Correct 47 ms 2820 KB Output is correct
17 Correct 272 ms 5376 KB Output is correct
18 Correct 195 ms 5200 KB Output is correct
19 Correct 164 ms 5224 KB Output is correct
20 Correct 206 ms 5208 KB Output is correct
21 Correct 492 ms 5940 KB Output is correct
22 Correct 538 ms 5896 KB Output is correct
23 Correct 457 ms 5796 KB Output is correct
24 Correct 440 ms 5968 KB Output is correct
25 Correct 741 ms 6480 KB Output is correct
26 Correct 1061 ms 150900 KB Output is correct
27 Correct 1326 ms 159460 KB Output is correct
28 Correct 1513 ms 129436 KB Output is correct
29 Correct 1503 ms 122296 KB Output is correct
30 Correct 1390 ms 169620 KB Output is correct
31 Correct 1145 ms 8432 KB Output is correct
32 Correct 1183 ms 137876 KB Output is correct