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 <iostream>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int MAXN = 4500;
char grid[MAXN][MAXN];
int dist[MAXN][MAXN];
int dX[] = {1, -1, 0, 0};
int dY[] = {0, 0, 1, -1};
int h, w;
int main(){
speedup
cin >> h >> w;
for (int i = 0; i < h; i++){
string s; cin >> s;
for (int j = 0; j < w; j++){
grid[i][j] = s[j];
}
}
deque<pair<int, int>> q;
q.push_back({0, 0});
for (int i = 0; i < MAXN; i++){
for (int j = 0; j < MAXN; j++){
dist[i][j] = 0;
}
}
dist[0][0] = 1;
int ans = 1;
while (!q.empty()){
auto&[x, y] = q.front(); q.pop_front();
ans = max(ans, dist[x][y]);
for (int i = 0; i < 4; i++){
int nX = x+dX[i], nY = y+dY[i];
if (nX >= 0 && nX < h && nY >= 0 && nY < w && grid[nX][nY] != '.' && dist[nX][nY] == 0){
if (grid[nX][nY] == grid[x][y]){
dist[nX][nY] = dist[x][y];
q.push_front({nX, nY});
}else{
dist[nX][nY] = dist[x][y]+1;
q.push_back({nX, nY});
}
}
}
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:39:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | auto&[x, y] = q.front(); q.pop_front();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |