이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll INF=1e18;
#define MottoHayaku ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
ll dist[105][105];
char dir='X';
vector<pll> ed[105][105];
void dijk(ll sx,ll sy,ll ex,ll ey)
{
queue<pll> q;
q.push({sx,sy});
dist[sx][sy]=0;
while(!q.empty())
{
pll p=q.front();q.pop();
for(auto u:ed[p.F][p.S])
{
if(dist[u.F][u.S]<=dist[p.F][p.S]+1) continue;
dist[u.F][u.S]=dist[p.F][p.S]+1;
if(u.F==ex&&u.S==ey)
{
if(u.F==p.F-1) dir=min(dir,'S');
else if(u.F==p.F+1) dir=min(dir,'N');
else if(u.S==p.S-1) dir=min(dir,'E');
else dir=min(dir,'W');
}
q.push(u);
}
}
}
string s[105];
int main()
{
MottoHayaku
ll n,m,sx,sy,ex,ey;
cin>>n>>m;
rep(i,n) cin>>s[i];
rep(i,n)
{
rep(j,m)
{
dist[i][j]=INF;
if(s[i][j]=='^') ed[i-1][j].pb({i,j});
if(s[i][j]=='v') ed[i+1][j].pb({i,j});
if(s[i][j]=='<') ed[i][j-1].pb({i,j});
if(s[i][j]=='>') ed[i][j+1].pb({i,j});
if(s[i][j]=='x') sx=i,sy=j;
if(s[i][j]=='o')
{
ex=i,ey=j;
ed[i-1][j].pb({i,j});
ed[i+1][j].pb({i,j});
ed[i][j-1].pb({i,j});
ed[i][j+1].pb({i,j});
}
}
}
dijk(sx,sy,ex,ey);
if(dist[ex][ey]==INF) cout<<":(\n";
else cout<<":)\n"<<dir<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
patkice.cpp: In function 'int main()':
patkice.cpp:67:19: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | if(dist[ex][ey]==INF) cout<<":(\n";
| ~~~~~~~~~~~^
patkice.cpp:67:19: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
patkice.cpp:66:9: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | dijk(sx,sy,ex,ey);
| ~~~~^~~~~~~~~~~~~
patkice.cpp:66:9: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |