#include <bits/stdc++.h>
using namespace std;
int w, h, ans;
char snow[4001][4001];
int check[4001][4001];
void dfs(int x, int y, int br)
{
if(x-1>0)
{
if(snow[x-1][y]==snow[x][y] and check[x-1][y]==0){check[x-1][y]=br; dfs(x-1, y, br);}
else if(snow[x-1][y]!='.')
{
if(check[x-1][y]==0)check[x-1][y]=br+1;
}
}
if(x+1<=h)
{
if(snow[x][y]==snow[x+1][y] and check[x+1][y]==0){check[x+1][y]=br; dfs(x+1, y, br);}
else if(snow[x+1][y]!='.')
{
if(check[x+1][y]==0)check[x+1][y]=br+1;
}
}
if(y-1>0)
{
if(snow[x][y]==snow[x][y-1] and check[x][y-1]==0){check[x][y-1]=br; dfs(x, y-1, br);}
else if(snow[x][y-1]!='.')
{
if(check[x][y-1]==0)check[x][y-1]=br+1;
}
}
if(y+1<=w)
{
if(snow[x][y]==snow[x][y+1] and check[x][y+1]==0){check[x][y+1]=br; dfs(x, y+1, br);}
else if(snow[x][y+1]!='.')
{
if(check[x][y+1]==0)check[x][y+1]=br+1;
}
}
return;
}
int main()
{
cin>>h>>w;
for(int i=1; i<=h; i++)
{
for(int j=1; j<=w; j++)cin>>snow[i][j];
}
check[1][1]=1;
for(int i=1; i<=h; i++)
{
for(int j=1; j<=w; j++)
{
if(snow[i][j]=='.')check[i][j]=-1;
else {dfs(i, j, check[i][j]); ans=max(ans, check[i][j]);}
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
614 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Runtime error |
544 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Incorrect |
12 ms |
8796 KB |
Output isn't correct |
5 |
Runtime error |
540 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
7 |
Runtime error |
573 ms |
1048576 KB |
Execution killed with signal 9 |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Runtime error |
536 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Runtime error |
574 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Incorrect |
4 ms |
4296 KB |
Output isn't correct |
12 |
Runtime error |
555 ms |
1048576 KB |
Execution killed with signal 9 |
13 |
Runtime error |
550 ms |
1048576 KB |
Execution killed with signal 9 |
14 |
Runtime error |
574 ms |
1048576 KB |
Execution killed with signal 9 |
15 |
Runtime error |
570 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Runtime error |
545 ms |
1048576 KB |
Execution killed with signal 9 |
17 |
Runtime error |
543 ms |
1048576 KB |
Execution killed with signal 9 |
18 |
Incorrect |
11 ms |
8796 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
556 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Runtime error |
597 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Runtime error |
1108 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Runtime error |
677 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Incorrect |
348 ms |
68884 KB |
Output isn't correct |
6 |
Incorrect |
1112 ms |
171552 KB |
Output isn't correct |
7 |
Runtime error |
543 ms |
1048576 KB |
Execution killed with signal 9 |
8 |
Runtime error |
550 ms |
1048576 KB |
Execution killed with signal 9 |
9 |
Runtime error |
553 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Runtime error |
531 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Runtime error |
551 ms |
1048576 KB |
Execution killed with signal 9 |
12 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
13 |
Runtime error |
603 ms |
1048576 KB |
Execution killed with signal 9 |
14 |
Runtime error |
613 ms |
1048576 KB |
Execution killed with signal 9 |
15 |
Runtime error |
583 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Runtime error |
578 ms |
1048576 KB |
Execution killed with signal 9 |
17 |
Runtime error |
673 ms |
1048576 KB |
Execution killed with signal 9 |
18 |
Runtime error |
682 ms |
1048576 KB |
Execution killed with signal 9 |
19 |
Runtime error |
664 ms |
1048576 KB |
Execution killed with signal 9 |
20 |
Runtime error |
641 ms |
1048576 KB |
Execution killed with signal 9 |
21 |
Runtime error |
857 ms |
1048576 KB |
Execution killed with signal 9 |
22 |
Incorrect |
346 ms |
68876 KB |
Output isn't correct |
23 |
Runtime error |
802 ms |
1048576 KB |
Execution killed with signal 9 |
24 |
Runtime error |
813 ms |
1048576 KB |
Execution killed with signal 9 |
25 |
Runtime error |
1065 ms |
1048576 KB |
Execution killed with signal 9 |
26 |
Runtime error |
991 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Correct |
1391 ms |
685668 KB |
Output is correct |
28 |
Incorrect |
1071 ms |
167608 KB |
Output isn't correct |
29 |
Incorrect |
1041 ms |
163496 KB |
Output isn't correct |
30 |
Incorrect |
1128 ms |
298932 KB |
Output isn't correct |
31 |
Runtime error |
875 ms |
1048576 KB |
Execution killed with signal 9 |
32 |
Runtime error |
1054 ms |
1048576 KB |
Execution killed with signal 9 |