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>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define pb push_back
#define mid (l+(r-l)/2)
#define f first
#define s second
const int N=2e5+5;
const int MOD=1e9+7;
const long long inf=INT64_MAX;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
void io(string name = ""){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
int x[4]={-1,0,1,0};
int y[4]={0,-1,0,1};
int n,m;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
vector<vector<char>>v(n,vector<char>(m));
vector<vector<int>>dep(n,vector<int>(m,0));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>v[i][j];
}
}
deque<array<int,2>>q;
int ans=0;
q.push_back({0,0});
dep[0][0]=1;
while(q.size()){
int a=q.front()[0],b=q.front()[1];
q.pop_front();
ans=max(ans,dep[a][b]);
for(int k=0;k<4;k++){
int i=a+x[k],j=b+y[k];
if(((i>=0&&i<n)&&(j>=0&&j<m)&&v[i][j]!='.')&&dep[i][j]==0){
if(v[a][b]==v[i][j]){dep[i][j]=dep[a][b];q.push_front({i,j});}
else{dep[i][j]=dep[a][b]+1;q.push_back({i,j});}
}
}
}
cout<<ans;
return 0;
}
Compilation message (stderr)
tracks.cpp: In function 'void io(std::string)':
tracks.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen((name+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen((name+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |