#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ff first
#define ss second
#define pii pair<int,int>
#define pb push_back
#define epb emplace_back
#define pll pair<ll,ll>
using namespace std;
int n,m;
char c[1001][1001];
int comp[1001][1001];
bool used[1001][1001];
bool used1[1000002];
int dn[1000002];
set<int> g[1000002];
int ans=1;
void dfs1(int x,int y,int ind){
used[x][y]=1;
comp[x][y]=ind;
for(int i=-1;i<=1;i++){
for(int j=-1;j<=1;j++){
if(i!=0&&j!=0)
continue;
if(i==0&&j==0)
continue;
if(x+i>=1&&x+i<=n&&y+j>=1&&y+j<=m){
if(used[x+i][y+j]==0&&c[x+i][y+j]==c[x][y]){
dfs1(x+i,y+j,ind);
}
}
}
}
}
void bfs(int das){
used1[das]=1;
queue<int> q;
q.push(das);
dn[das]=1;
while(!q.empty()){
int v=q.front();
q.pop();
for(int i:g[v]){
if(used1[i]==0){
used1[i]=1;
q.push(i);
dn[i]=dn[v]+1;
ans=max(ans,dn[i]);
}
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>c[i][j];
}
}
int ind=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(c[i][j]!='*'&&used[i][j]==0){
dfs1(i,j,ind);
ind++;
}
}
}
for(int i=1;i<n;i++){
for(int j=1;j<m;j++){
int f1=comp[i][j];
int f2=comp[i][j+1];
int f3=comp[i+1][j];
if(f1!=0&&f2!=0){
g[f1].insert(f2);
g[f2].insert(f1);
}
if(f1!=0&&f3!=0){
g[f1].insert(f3);
g[f3].insert(f1);
}
}
}
bfs(1);
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
57548 KB |
Output isn't correct |
2 |
Incorrect |
22 ms |
47408 KB |
Output isn't correct |
3 |
Incorrect |
23 ms |
47672 KB |
Output isn't correct |
4 |
Correct |
46 ms |
53176 KB |
Output is correct |
5 |
Incorrect |
40 ms |
52848 KB |
Output isn't correct |
6 |
Incorrect |
23 ms |
47428 KB |
Output isn't correct |
7 |
Incorrect |
23 ms |
47600 KB |
Output isn't correct |
8 |
Correct |
23 ms |
47648 KB |
Output is correct |
9 |
Incorrect |
27 ms |
48256 KB |
Output isn't correct |
10 |
Incorrect |
37 ms |
51660 KB |
Output isn't correct |
11 |
Correct |
30 ms |
49364 KB |
Output is correct |
12 |
Incorrect |
42 ms |
51888 KB |
Output isn't correct |
13 |
Incorrect |
40 ms |
52864 KB |
Output isn't correct |
14 |
Incorrect |
39 ms |
52740 KB |
Output isn't correct |
15 |
Incorrect |
76 ms |
59120 KB |
Output isn't correct |
16 |
Incorrect |
77 ms |
57508 KB |
Output isn't correct |
17 |
Incorrect |
82 ms |
62496 KB |
Output isn't correct |
18 |
Correct |
45 ms |
53192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
60 ms |
97620 KB |
Execution killed with signal 11 |
2 |
Runtime error |
122 ms |
98932 KB |
Execution killed with signal 11 |
3 |
Runtime error |
268 ms |
101780 KB |
Execution killed with signal 11 |
4 |
Runtime error |
159 ms |
99740 KB |
Execution killed with signal 11 |
5 |
Runtime error |
209 ms |
100784 KB |
Execution killed with signal 11 |
6 |
Runtime error |
262 ms |
101708 KB |
Execution killed with signal 11 |
7 |
Runtime error |
60 ms |
97584 KB |
Execution killed with signal 11 |
8 |
Runtime error |
60 ms |
97616 KB |
Execution killed with signal 11 |
9 |
Incorrect |
30 ms |
48420 KB |
Output isn't correct |
10 |
Incorrect |
26 ms |
48212 KB |
Output isn't correct |
11 |
Runtime error |
60 ms |
97628 KB |
Execution killed with signal 11 |
12 |
Incorrect |
31 ms |
51276 KB |
Output isn't correct |
13 |
Runtime error |
122 ms |
98996 KB |
Execution killed with signal 11 |
14 |
Incorrect |
221 ms |
95192 KB |
Output isn't correct |
15 |
Incorrect |
355 ms |
123400 KB |
Output isn't correct |
16 |
Incorrect |
143 ms |
71584 KB |
Output isn't correct |
17 |
Runtime error |
163 ms |
99772 KB |
Execution killed with signal 11 |
18 |
Runtime error |
165 ms |
99760 KB |
Execution killed with signal 11 |
19 |
Runtime error |
159 ms |
99748 KB |
Execution killed with signal 11 |
20 |
Runtime error |
158 ms |
99772 KB |
Execution killed with signal 11 |
21 |
Runtime error |
208 ms |
100800 KB |
Execution killed with signal 11 |
22 |
Runtime error |
213 ms |
100824 KB |
Execution killed with signal 11 |
23 |
Runtime error |
213 ms |
100812 KB |
Execution killed with signal 11 |
24 |
Runtime error |
203 ms |
100588 KB |
Execution killed with signal 11 |
25 |
Runtime error |
261 ms |
101596 KB |
Execution killed with signal 11 |
26 |
Runtime error |
237 ms |
101076 KB |
Execution killed with signal 11 |
27 |
Runtime error |
269 ms |
101708 KB |
Execution killed with signal 11 |
28 |
Runtime error |
258 ms |
101652 KB |
Execution killed with signal 11 |
29 |
Runtime error |
258 ms |
101588 KB |
Execution killed with signal 11 |
30 |
Runtime error |
263 ms |
101676 KB |
Execution killed with signal 11 |
31 |
Runtime error |
220 ms |
100936 KB |
Execution killed with signal 11 |
32 |
Runtime error |
283 ms |
101652 KB |
Execution killed with signal 11 |