이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
vector<vector<int>> field(h, vector<int>(w, 0)), filled(h, vector<int>(w, 0));
for (int i = 0; i < h; ++i) {
string line;
cin >> line;
for (int j = 0; j < w; ++j) field[i][j] = (line[j] == '.' ? -1 : (line[j] == 'R' ? 1 : 2));
}
int r = 0;
vector<vector<int>> next;
vector<int> first{0, 0};
next.push_back(first);
while (!next.empty()) {
queue<vector<int>> q;
for (vector<int> go : next) q.push(go);
next.clear();
while (!q.empty()) {
vector<int> square = q.front();
q.pop();
for (int a = -1; a < 2; a += 2) {
int newX = square[0] + a, newY = square[1];
if (newX < 0 || newY < 0 || newX >= h || newY >= w) continue;
if (filled[newX][newY] > 0 || field[newX][newY] < 0) continue;
vector<int> add{newX, newY};
if (field[newX][newY] == field[square[0]][square[1]]) q.push(add);
else next.push_back(add);
}
for (int a = -1; a < 2; a += 2) {
int newX = square[0], newY = square[1] + a;
if (newX < 0 || newY < 0 || newX >= h || newY >= w) continue;
if (filled[newX][newY] > 0 || field[newX][newY] < 0) continue;
// vector<int> add{newX, newY};
// if (field[newX][newY] == field[square[0]][square[1]]) q.push(add);
// else next.push_back(add);
}
// filled[square[0]][square[1]] = 1;
}
r++;
}
cout << r;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |