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 all(x) begin(x), end(x)
#define allr(x, r) begin(x), begin(x) + (r)
#define mp make_pair
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
int xs[]{0, 1, 0, -1}, ys[]{-1, 0, 1, 0};
int main()
{
#if defined(DEBUG) && !defined(ONLINE_JUDGE)
// DEBUG
cerr << "DEBUG flag set - see test.out for output\n";
freopen("/home/chuang/shared-drives/F:/repos/cp/ois/boi13/test.in", "r", stdin);
freopen("/home/chuang/shared-drives/F:/repos/cp/ois/boi13/test.out", "w", stdout);
#else
cin.tie(0)->sync_with_stdio(false);
#endif
int H, W;
cin >> H >> W;
vector<vi> dist(H);
for (auto &r : dist)
r.assign(W, 0);
dist[0][0] = 1;
vector<string> grid(H);
for (auto &r : grid)
cin >> r;
deque<pi> bfs;
bfs.push_back(mp(0, 0));
int ans = 1;
while (!bfs.empty())
{
pi cell = bfs.front();
bfs.pop_front();
ans = max(ans, dist[cell.first][cell.second]);
for (int i = 0; i < 4; i++)
{
int r = cell.first + xs[i];
int c = cell.second + ys[i];
if (r >= 0 && r < H && c >= 0 && c < W && grid[r][c] != '.' && dist[r][c] == 0)
{
if (grid[cell.first][cell.second] == grid[r][c])
{
dist[r][c] = dist[cell.first][cell.second];
bfs.push_front(mp(r, c));
}
else
{
dist[r][c] = dist[cell.first][cell.second] + 1;
bfs.push_back(mp(r, c));
}
}
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |