#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
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 |
1 |
Correct |
13 ms |
2916 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
7 ms |
2436 KB |
Output is correct |
5 |
Correct |
3 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
1120 KB |
Output is correct |
11 |
Correct |
4 ms |
848 KB |
Output is correct |
12 |
Correct |
4 ms |
1532 KB |
Output is correct |
13 |
Correct |
4 ms |
1104 KB |
Output is correct |
14 |
Correct |
3 ms |
1104 KB |
Output is correct |
15 |
Correct |
13 ms |
3000 KB |
Output is correct |
16 |
Correct |
14 ms |
2896 KB |
Output is correct |
17 |
Correct |
11 ms |
2700 KB |
Output is correct |
18 |
Correct |
7 ms |
2264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1104 KB |
Output is correct |
2 |
Correct |
57 ms |
15700 KB |
Output is correct |
3 |
Correct |
375 ms |
157288 KB |
Output is correct |
4 |
Correct |
134 ms |
37160 KB |
Output is correct |
5 |
Correct |
257 ms |
88620 KB |
Output is correct |
6 |
Correct |
785 ms |
184892 KB |
Output is correct |
7 |
Correct |
3 ms |
1104 KB |
Output is correct |
8 |
Correct |
2 ms |
1280 KB |
Output is correct |
9 |
Correct |
3 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
1104 KB |
Output is correct |
12 |
Correct |
1 ms |
592 KB |
Output is correct |
13 |
Correct |
51 ms |
15696 KB |
Output is correct |
14 |
Correct |
26 ms |
9296 KB |
Output is correct |
15 |
Correct |
23 ms |
10064 KB |
Output is correct |
16 |
Correct |
33 ms |
6636 KB |
Output is correct |
17 |
Correct |
142 ms |
40268 KB |
Output is correct |
18 |
Correct |
93 ms |
39752 KB |
Output is correct |
19 |
Correct |
84 ms |
37192 KB |
Output is correct |
20 |
Correct |
68 ms |
34120 KB |
Output is correct |
21 |
Correct |
184 ms |
91800 KB |
Output is correct |
22 |
Correct |
218 ms |
88720 KB |
Output is correct |
23 |
Correct |
254 ms |
76360 KB |
Output is correct |
24 |
Correct |
202 ms |
89636 KB |
Output is correct |
25 |
Correct |
396 ms |
157320 KB |
Output is correct |
26 |
Correct |
460 ms |
221440 KB |
Output is correct |
27 |
Correct |
661 ms |
214336 KB |
Output is correct |
28 |
Correct |
760 ms |
184868 KB |
Output is correct |
29 |
Correct |
758 ms |
186224 KB |
Output is correct |
30 |
Correct |
689 ms |
195164 KB |
Output is correct |
31 |
Correct |
513 ms |
101584 KB |
Output is correct |
32 |
Correct |
554 ms |
193360 KB |
Output is correct |