이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |