#include <bits/stdc++.h>
using namespace std;
#define int long long
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
vector<string> snow(4000);
vector<vector<int>> depth(4000,vector<int>(4000));
int n,m,ans=1;
bool inside(int x, int y)
{
if(-1<x&&x<n&&-1<y&&y<m&&snow[x][y]!='.')
{
return true;
}
return false;
}
signed main() {
iostream::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i=0;i<n;i++)
{
cin >> snow[i];
}
depth[0][0]=1;
deque<pair<int,int>> q;
q.push_back({0,0});
while(q.size())
{
pair<int,int> now = q.front();
q.pop_front();
ans = max(ans,depth[now.first][now.second]);
for(int i=0;i<4;i++)
{
int x=now.first + dx[i],y=now.second + dy[i];
if(inside(x,y)&&depth[x][y]==0)
{
if(snow[x][y]==snow[now.first][now.second])
{
depth[x][y]=depth[now.first][now.second];
q.push_front({x,y});
}
else
{
depth[x][y]=depth[now.first][now.second]+1;
q.push_back({x,y});
}
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
126412 KB |
Output is correct |
2 |
Correct |
49 ms |
125792 KB |
Output is correct |
3 |
Correct |
48 ms |
125772 KB |
Output is correct |
4 |
Correct |
53 ms |
126540 KB |
Output is correct |
5 |
Correct |
52 ms |
125904 KB |
Output is correct |
6 |
Correct |
48 ms |
125836 KB |
Output is correct |
7 |
Correct |
48 ms |
125836 KB |
Output is correct |
8 |
Correct |
48 ms |
125768 KB |
Output is correct |
9 |
Correct |
48 ms |
125772 KB |
Output is correct |
10 |
Correct |
49 ms |
125888 KB |
Output is correct |
11 |
Correct |
54 ms |
126024 KB |
Output is correct |
12 |
Correct |
51 ms |
126008 KB |
Output is correct |
13 |
Correct |
49 ms |
125992 KB |
Output is correct |
14 |
Correct |
49 ms |
126004 KB |
Output is correct |
15 |
Correct |
54 ms |
126384 KB |
Output is correct |
16 |
Correct |
56 ms |
126372 KB |
Output is correct |
17 |
Correct |
54 ms |
126284 KB |
Output is correct |
18 |
Correct |
52 ms |
126504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
125892 KB |
Output is correct |
2 |
Correct |
74 ms |
128924 KB |
Output is correct |
3 |
Correct |
188 ms |
159176 KB |
Output is correct |
4 |
Correct |
89 ms |
133416 KB |
Output is correct |
5 |
Correct |
165 ms |
144372 KB |
Output is correct |
6 |
Correct |
590 ms |
186644 KB |
Output is correct |
7 |
Correct |
50 ms |
125856 KB |
Output is correct |
8 |
Correct |
48 ms |
125848 KB |
Output is correct |
9 |
Correct |
51 ms |
125948 KB |
Output is correct |
10 |
Correct |
49 ms |
125876 KB |
Output is correct |
11 |
Correct |
52 ms |
125840 KB |
Output is correct |
12 |
Correct |
50 ms |
125844 KB |
Output is correct |
13 |
Correct |
81 ms |
128932 KB |
Output is correct |
14 |
Correct |
66 ms |
127688 KB |
Output is correct |
15 |
Correct |
64 ms |
127816 KB |
Output is correct |
16 |
Correct |
63 ms |
127168 KB |
Output is correct |
17 |
Correct |
122 ms |
134028 KB |
Output is correct |
18 |
Correct |
100 ms |
133900 KB |
Output is correct |
19 |
Correct |
92 ms |
133372 KB |
Output is correct |
20 |
Correct |
81 ms |
132848 KB |
Output is correct |
21 |
Correct |
133 ms |
144920 KB |
Output is correct |
22 |
Correct |
190 ms |
144260 KB |
Output is correct |
23 |
Correct |
194 ms |
141904 KB |
Output is correct |
24 |
Correct |
131 ms |
144484 KB |
Output is correct |
25 |
Correct |
382 ms |
159180 KB |
Output is correct |
26 |
Correct |
398 ms |
251544 KB |
Output is correct |
27 |
Correct |
466 ms |
212344 KB |
Output is correct |
28 |
Correct |
576 ms |
186440 KB |
Output is correct |
29 |
Correct |
574 ms |
183264 KB |
Output is correct |
30 |
Correct |
517 ms |
194180 KB |
Output is correct |
31 |
Correct |
460 ms |
147860 KB |
Output is correct |
32 |
Correct |
418 ms |
189864 KB |
Output is correct |