#include<bits/stdc++.h>
using namespace std;
int n,m;
string t[1001];
int ans;
int d[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
int volt[1001][1001];
void dfs(int x, int y, int cnt) {
//cerr<<x<<" "<<y<<" "<<cnt<<"\n";
volt[x][y]=1;
ans=max(ans, cnt);
for(int i=0;i<4;++i) {
int nx=x+d[i][0], ny=y+d[i][1];
if(nx>=0 && ny>=0 && nx<n && ny<m && !volt[nx][ny]) {
if(t[nx][ny]==t[x][y]) dfs(nx,ny,cnt);
}
}
for(int i=0;i<4;++i) {
int nx=x+d[i][0], ny=y+d[i][1];
if(nx>=0 && ny>=0 && nx<n && ny<m && !volt[nx][ny]) {
if(t[nx][ny]!=t[x][y] && t[nx][ny]!='*') dfs(nx,ny,cnt+1);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;++i) cin>>t[i];
dfs(n-1,m-1,1);
cout<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |