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 endl '\n'
/**
* IDEA:
*/
const int sz = 4e3 + 5;
int m, n;
int a[sz][sz], vi[sz][sz], d[sz][sz];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool valid(int x, int y){
return (x >= 1 && x <= m && y >= 1 && y <= n);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("main.inp","r",stdin);
// freopen("main.out","w",stdout);
cin>>m>>n;
for(int i=1;i<=m;++i){
for(int j=1;j<=n;++j){
char c;
cin>>c;
if(c == '.'){
a[i][j] == -1;
}
if(c == 'F'){
a[i][j] = 1;
}
else{
a[i][j] = 2;
}
}
}
deque<pair<int,int>> q;
q.push_front({1, 1});
vi[1][1] = 1;
d[1][1] = 1;
int ans = 0;
while(q.size()){
int x = q.front().first;
int y = q.front().second;
q.pop_front();
ans = max(ans, d[x][y]);
for(int i=0;i<4;++i){
int u = x + dx[i];
int v = y + dy[i];
int c = (a[x][y] != a[u][v]);
if(valid(u, v) && !vi[u][v]){
d[u][v] = d[x][y] + c;
vi[u][v] = 1;
if(!c){
q.push_front({u, v});
}
else{
q.push_back({u, v});
}
}
}
}
cout<<ans;
return 0;
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:33:25: warning: statement has no effect [-Wunused-value]
33 | a[i][j] == -1;
| ~~~~~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |