#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector<vc>
#define vvb vector<vb>
#define si set<int>
#define mii map<int,int>
const int mod=1e9+7;
const int N=2e5+1;
const int LN=LLONG_MAX/10;
int dx[4]{1,-1,0,0},dy[4]{0,0,1,-1};
int n,m,depth[4000][4000],ans=1;
string snow[4000];
bool inside(int x,int y){
return (x>-1 and x<n and y>-1 and y<m and snow[x][y]!='.');
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>snow[i];
deque<pii> Q;
Q.push_back({0,0});
depth[0][0]=1;
while(Q.size()){
pii c=Q.front();
Q.pop_front();
ans=max(ans,depth[c.first][c.second]);
for(int i=0;i<4;i++){
int x=c.first+dx[i],y=c.second+dy[i];
if(inside(x,y) and depth[x][y]==0){
if(snow[x][y]==snow[c.first][c.second]){
depth[x][y]=depth[c.first][c.second];
Q.push_front({x,y});
}
else{
depth[x][y]=depth[c.first][c.second]+1;
Q.push_back({x,y});
}
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4820 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
7 ms |
4172 KB |
Output is correct |
5 |
Correct |
3 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Correct |
1 ms |
840 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
5 ms |
2516 KB |
Output is correct |
13 |
Correct |
3 ms |
2260 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
15 |
Correct |
10 ms |
4432 KB |
Output is correct |
16 |
Correct |
13 ms |
4820 KB |
Output is correct |
17 |
Correct |
11 ms |
4556 KB |
Output is correct |
18 |
Correct |
8 ms |
4284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15908 KB |
Output is correct |
2 |
Correct |
34 ms |
15052 KB |
Output is correct |
3 |
Correct |
168 ms |
93540 KB |
Output is correct |
4 |
Correct |
62 ms |
43060 KB |
Output is correct |
5 |
Correct |
140 ms |
69264 KB |
Output is correct |
6 |
Correct |
566 ms |
186056 KB |
Output is correct |
7 |
Correct |
11 ms |
16672 KB |
Output is correct |
8 |
Correct |
10 ms |
15956 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
13 ms |
16332 KB |
Output is correct |
12 |
Correct |
2 ms |
1232 KB |
Output is correct |
13 |
Correct |
36 ms |
15052 KB |
Output is correct |
14 |
Correct |
20 ms |
9932 KB |
Output is correct |
15 |
Correct |
19 ms |
14248 KB |
Output is correct |
16 |
Correct |
19 ms |
6432 KB |
Output is correct |
17 |
Correct |
91 ms |
32936 KB |
Output is correct |
18 |
Correct |
73 ms |
47652 KB |
Output is correct |
19 |
Correct |
81 ms |
43096 KB |
Output is correct |
20 |
Correct |
57 ms |
27216 KB |
Output is correct |
21 |
Correct |
103 ms |
61072 KB |
Output is correct |
22 |
Correct |
140 ms |
69456 KB |
Output is correct |
23 |
Correct |
186 ms |
56284 KB |
Output is correct |
24 |
Correct |
107 ms |
59220 KB |
Output is correct |
25 |
Correct |
402 ms |
158928 KB |
Output is correct |
26 |
Correct |
355 ms |
235728 KB |
Output is correct |
27 |
Correct |
452 ms |
212152 KB |
Output is correct |
28 |
Correct |
550 ms |
186108 KB |
Output is correct |
29 |
Correct |
571 ms |
183100 KB |
Output is correct |
30 |
Correct |
531 ms |
191520 KB |
Output is correct |
31 |
Correct |
517 ms |
115336 KB |
Output is correct |
32 |
Correct |
406 ms |
183376 KB |
Output is correct |