Submission #1091282

#TimeUsernameProblemLanguageResultExecution timeMemory
1091282stdfloatTracks in the Snow (BOI13_tracks)C++17
45.31 / 100
2095 ms38404 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

vector<int> X = {-1, 0, 1, 0}, Y = {0, 1, 0, -1};

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n, m;
	cin >> n >> m;

	vector<string> a(n);
	for (auto &i : a)
		cin >> i;

	char c = a[0][0];
	vector<vector<bool>> mp(n, vector<bool>(m)); mp[0][0] = true;
	for (int z = 0; ; z++) {
		bool tr = !z;
		queue<pair<int, int>> q;
		vector<vector<bool>> vis(n, vector<bool>(m));
		q.push({0, 0}); vis[0][0] = true;
		while (!q.empty()) {
			auto [x, y] = q.front(); q.pop();

			for (int i = 0; i < 4; i++) {
				int nx = x + X[i], ny = y + Y[i];
				if (0 <= min(nx, ny) && nx < n && ny < m && !vis[nx][ny] && (mp[nx][ny] || c == a[nx][ny])) {
					q.push({nx, ny});
					tr |= !mp[nx][ny];
					vis[nx][ny] = mp[nx][ny] = true;
				}
			}
		}

		c = (c == 'F' ? 'R' : 'F');

		if (!tr) return cout << z, 0;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...