이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |