This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |