이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define idata vector<int>
#define imap vector<idata>
#define EMPTY -1
#define FOX 0
#define RABBIT 1
imap positions;
int height, width;
imap visited;
int stage = 1;
bool dfs (int x, int y, int type) {
if (positions[x][y] == EMPTY) return true;
if (positions[x][y] != type
&& visited [x][y] == EMPTY) return false;
if (visited[x][y] == stage) return true;
visited[x][y] = stage;
bool result = true;
if (x != 0) result &= dfs(x - 1, y, type);
if (y != 0) result &= dfs(x, y - 1, type);
if (x != height - 1) result &= dfs(x + 1, y, type);
if (y != width - 1) result &= dfs(x, y + 1, type);
return result;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> height >> width;
positions.resize( height, idata(width, EMPTY) );
visited .resize( height, idata(width, EMPTY) );
for (int h = 0; h < height; h ++) {
string buffer;
cin >> buffer;
for (int w = 0; w < width; w ++) {
int mu = EMPTY;
if (buffer[w] == 'F') mu = FOX;
if (buffer[w] == 'R') mu = RABBIT;
positions[h][w] = mu;
}
}
int count = 1;
while (!dfs(0, 0, (positions[0][0] + count + 1) & 1)) {
count ++;
stage ++;
}
cout << count << endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |