이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
int dx[4]={0,1,-1,0};
int dy[4]={-1,0,0,1};
const int maxn=4005;
string s[maxn];
int d[maxn][maxn];
int n,m;
bool check(int x,int y)
{
return ((x>-1)&&(x<n)&&(y>-1)&&(y<m)&&(s[x][y]!='.')&&(d[x][y]==0));
}
main()
{
cin>>n>>m;
for(int i=0;i<n;i++)cin>>s[i];
d[0][0]=1;
deque<ii>dq;
int ans=0;
dq.push_back({0,0});
while(dq.size()){
ii c=dq.front();
dq.pop_front();
ans=max(ans,d[c.fi][c.se]);
for(int i=0;i<4;i++){
int x=c.fi+dx[i];
int y=c.se+dy[i];
if(check(x,y)){
if(s[c.fi][c.se]!=s[x][y]){
d[x][y]=d[c.fi][c.se]+1;
dq.push_back({x,y});
}
else{
d[x][y]=d[c.fi][c.se];
dq.push_front({x,y});
}
}
}
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |