Submission #843137

# Submission time Handle Problem Language Result Execution time Memory
843137 2023-09-03T17:51:39 Z Mizo_Compiler Tracks in the Snow (BOI13_tracks) C++14
49.5833 / 100
728 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
const int N = 4000;
int n, m, ans = 1;
char c[N][N];
bool fc[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
vector<pair<int, int>> f, r;
bool vis[N][N];

void dfs(int i, int j) {
	fc[i][j] = true;
	vis[i][j] = true;
	for (int ii = 0; ii < 4; ii++) {
		int nx = i + dx[ii], ny = j + dy[ii];
		if (nx < 0 || ny < 0 || nx >= n || ny >= m)continue;
		if (c[nx][ny] == c[0][0]) {
			if (!fc[nx][ny])dfs(nx, ny);
		} else if (!vis[nx][ny]) {
			if (c[nx][ny] == 'F')f.pb({nx, ny});
			else r.pb({nx, ny});
			vis[nx][ny] = true;
		}
	}
}

int main () {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> c[i][j];
		}
	}
	dfs(0, 0);
	char cur = 'R';
	if (c[0][0] == cur)cur = 'F';
	while (!f.empty() || !r.empty()) {
		if (cur == 'R') {
			if (!r.empty())ans++;
			while (!r.empty()) {
				int x = r.back().F, y = r.back().S;
				r.pop_back();
				for (int i = 0; i < 4; i++) {
					int nx = x + dx[i], ny = y + dy[i];
					if (nx < 0 || ny < 0 || nx >= n || ny >= m)continue;
					if (vis[nx][ny])continue;
					vis[nx][ny] = true;
					if (c[nx][ny] == 'R')r.pb({nx, ny});
					else if (c[nx][ny] == 'F')f.pb({nx, ny});
				}
			}
		} else {
			if (!f.empty()) {
				ans++;
			}
			while (!f.empty()) {
				int x = f.back().F, y = f.back().S;
				f.pop_back();
				for (int i = 0; i < 4; i++) {
					int nx = x + dx[i], ny = y + dy[i];
					if (nx < 0 || ny < 0 || nx >= n || ny >= m)continue;
					if (vis[nx][ny])continue;
					vis[nx][ny] = true;
					if (c[nx][ny] == 'R')r.pb({nx, ny});
					else if (c[nx][ny] == 'F')f.pb({nx, ny});
				}
			}
		}
		if (cur == 'F')cur = 'R';
		else cur = 'F';
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10076 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Incorrect 1 ms 4700 KB Output isn't correct
4 Correct 6 ms 11224 KB Output is correct
5 Correct 3 ms 5724 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Incorrect 1 ms 4700 KB Output isn't correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 3 ms 7004 KB Output is correct
12 Correct 4 ms 7004 KB Output is correct
13 Correct 3 ms 5724 KB Output is correct
14 Correct 4 ms 5724 KB Output is correct
15 Correct 11 ms 9788 KB Output is correct
16 Correct 9 ms 10076 KB Output is correct
17 Correct 8 ms 9428 KB Output is correct
18 Correct 7 ms 11232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 46736 KB Output isn't correct
2 Correct 39 ms 19292 KB Output is correct
3 Incorrect 243 ms 48340 KB Output isn't correct
4 Correct 56 ms 24984 KB Output is correct
5 Incorrect 139 ms 38616 KB Output isn't correct
6 Correct 485 ms 101936 KB Output is correct
7 Incorrect 10 ms 47704 KB Output isn't correct
8 Incorrect 10 ms 46684 KB Output isn't correct
9 Incorrect 2 ms 5212 KB Output isn't correct
10 Incorrect 2 ms 4956 KB Output isn't correct
11 Incorrect 10 ms 47376 KB Output isn't correct
12 Incorrect 1 ms 6744 KB Output isn't correct
13 Correct 39 ms 19160 KB Output is correct
14 Incorrect 22 ms 12888 KB Output isn't correct
15 Incorrect 18 ms 15964 KB Output isn't correct
16 Correct 17 ms 7004 KB Output is correct
17 Incorrect 91 ms 28628 KB Output isn't correct
18 Incorrect 66 ms 26328 KB Output isn't correct
19 Correct 59 ms 24912 KB Output is correct
20 Incorrect 54 ms 25436 KB Output isn't correct
21 Incorrect 141 ms 41040 KB Output isn't correct
22 Incorrect 147 ms 38772 KB Output isn't correct
23 Incorrect 165 ms 32200 KB Output isn't correct
24 Incorrect 146 ms 41284 KB Output isn't correct
25 Incorrect 383 ms 48320 KB Output isn't correct
26 Runtime error 728 ms 1048576 KB Execution killed with signal 9
27 Correct 593 ms 358624 KB Output is correct
28 Correct 490 ms 102060 KB Output is correct
29 Correct 491 ms 110896 KB Output is correct
30 Correct 452 ms 109260 KB Output is correct
31 Correct 317 ms 42696 KB Output is correct
32 Correct 365 ms 65272 KB Output is correct