#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(){
io("local");
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
2 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
3 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
4 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
5 |
Runtime error |
3 ms |
528 KB |
Execution killed with signal 11 |
6 |
Runtime error |
3 ms |
760 KB |
Execution killed with signal 11 |
7 |
Runtime error |
4 ms |
592 KB |
Execution killed with signal 11 |
8 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
9 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
10 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
11 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
12 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
13 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
14 |
Runtime error |
4 ms |
592 KB |
Execution killed with signal 11 |
15 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
16 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
17 |
Runtime error |
3 ms |
540 KB |
Execution killed with signal 11 |
18 |
Runtime error |
3 ms |
608 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
2 |
Runtime error |
2 ms |
608 KB |
Execution killed with signal 11 |
3 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
4 |
Runtime error |
2 ms |
544 KB |
Execution killed with signal 11 |
5 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
6 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
7 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
8 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
9 |
Runtime error |
4 ms |
604 KB |
Execution killed with signal 11 |
10 |
Runtime error |
3 ms |
608 KB |
Execution killed with signal 11 |
11 |
Runtime error |
3 ms |
760 KB |
Execution killed with signal 11 |
12 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
13 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
14 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
15 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
16 |
Runtime error |
3 ms |
700 KB |
Execution killed with signal 11 |
17 |
Runtime error |
4 ms |
760 KB |
Execution killed with signal 11 |
18 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
19 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
20 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
21 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
22 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
23 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
24 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
25 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
26 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
27 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 11 |
28 |
Runtime error |
3 ms |
608 KB |
Execution killed with signal 11 |
29 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
30 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
31 |
Runtime error |
2 ms |
608 KB |
Execution killed with signal 11 |
32 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |