This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/BOI13_tracks
#include <bits/stdc++.h>
using namespace std;
#define tiii tuple<int, int, int>
#define mp make_pair
#define mt make_tuple
#define maxHW 4000
bool seen[maxHW][maxHW];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int h, w;
cin >> h >> w;
vector<string> grid(h);
for (int i = 0; i < h; i++) {
cin >> grid[i];
}
int ans = 0;
deque<tiii> Q({mt(0, 0, 1)});
while (!Q.empty()) {
auto [r, c, depth] = Q.front(); Q.pop_front();
ans = max(ans, depth);
seen[r][c] = true;
for (auto [nr, nc] : {mp(r + 1, c), mp(r - 1, c), mp(r, c + 1), mp(r, c - 1)}) {
if (0 <= nr && nr < h && 0 <= nc && nc < w && !seen[nr][nc] && grid[nr][nc] != '.') {
if (grid[nr][nc] == grid[r][c]) {
Q.push_front(mt(nr, nc, depth));
}
else {
Q.push_back(mt(nr, nc, depth + 1));
}
}
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |