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<deque>
using namespace std;
const int maxn = 4005;
int n,m,ans,val[maxn][maxn];
char arr[maxn][maxn];
deque<pair<int,int> > bfs;
void goTo(int oX, int oY, int x, int y) {
if(x < 0 || x >= n || y < 0 || y >= m) return;
if(val[x][y] != 0 || arr[x][y] == '.') return;
if(arr[oX][oY] == arr[x][y]) {
bfs.push_front(make_pair(x,y));
val[x][y] = val[oX][oY];
}
else {
bfs.push_back(make_pair(x,y));
val[x][y] = val[oX][oY]+1;
}
}
int main () {
scanf("%d%d",&n,&m);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
scanf(" %c",&arr[i][j]);
}
}
val[0][0] = 1;
bfs.push_front(make_pair(0,0));
while(bfs.size() > 0) {
pair<int,int> pos = bfs.front();
bfs.pop_front();
ans = max(ans,val[pos.first][pos.second]);
goTo(pos.first,pos.second,pos.first-1,pos.second);
goTo(pos.first,pos.second,pos.first+1,pos.second);
goTo(pos.first,pos.second,pos.first,pos.second-1);
goTo(pos.first,pos.second,pos.first,pos.second+1);
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
tracks.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf(" %c",&arr[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |