Submission #1091285

#TimeUsernameProblemLanguageResultExecution timeMemory
1091285stdfloatTracks in the Snow (BOI13_tracks)C++17
100 / 100
635 ms40444 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];
	queue<pair<int, int>> q;
	vector<vector<bool>> mp(n, vector<bool>(m));
	q.push({0, 0}); mp[0][0] = true;
	for (int z = 1; ; z++) {
		queue<pair<int, int>> nq;
		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 && !mp[nx][ny] && a[nx][ny] != '.') {
					mp[nx][ny] = true;
					(c == a[nx][ny] ? q : nq).push({nx, ny});
				}
			}
		}

		if (nq.empty()) return cout << z, 0;

		q = nq;
		c = (c == 'F' ? 'R' : 'F');
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...