이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
short n,m,d[4005][4005],u,v,dx[]={1,-1,0,0},dy[]={0,0,1,-1},x,y,mx=-1;
char s[4005][4005];
priority_queue<tuple<short,short,short> > pq;
int main()
{
scanf("%hd%hd",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%s",s[i]+1);
for(int j=1;j<=m;j++)
{
d[i][j]=20000;
}
}
d[1][1]=1;
pq.push({0,1,1});
while(!pq.empty())
{
u=get<1>(pq.top());
v=get<2>(pq.top());
mx=max(mx,d[u][v]);
pq.pop();
for(int i=0;i<4;i++)
{
x=u+dx[i];
y=v+dy[i];
if(x>=1&&x<=n&&y>=1&&y<=m)
{
if(s[x][y]!='.')
{
if(s[x][y]!=s[u][v])
{
if(d[u][v]+1<d[x][y])
{
d[x][y]=d[u][v]+1;
pq.push({-d[x][y],x,y});
}
}else
{
if(d[u][v]<d[x][y])
{
d[x][y]=d[u][v];
pq.push({-d[x][y],x,y});
}
}
}
}
}
}
printf("%hd\n",mx);
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'int main()':
tracks.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | scanf("%hd%hd",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~
tracks.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%s",s[i]+1);
| ~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |