이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
const int N = 3e4+10;
const int M = 3e2+10;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;
multiset<int>vis[N];
queue<pair<pii,int>>que;
vector<int>vec[N];
int n,m,dis[N];
int bfs(int st,int end){
for(int i=1;i<=n;i++)
dis[i] = INF;
dis[st] = 0;
que.push({{st,0},0});
while(!que.empty()){
int u = que.front().F.F,dis = que.front().F.S;
int p = que.front().S;
if(u==end)
return dis;
que.pop();
vec[u].push_back(p);
for(auto x:vec[u]){
if(u-x>=1)
if(vis[u-x].find(x)==vis[u-x].end())
que.push({{u-x,dis+1},x}),vis[u-x].insert(x);
if(u+x<=n)
if(vis[u+x].find(x)==vis[u+x].end())
que.push({{u+x,dis+1},x}),vis[u+x].insert(x);
}
vec[u].pop_back();
}
return -1;
}
int main(){
//freopen("out.txt","w",stdout);
scanf("%d%d",&n,&m);
int start,end;
for(int i=1;i<=m;i++){
int p,pos;
pos++;
scanf("%d%d",&pos,&p);
vec[pos].push_back(p);
if(i==1)start = pos;
if(i==2)end = pos;
}
printf("%d\n",bfs(start,end));
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d",&pos,&p);
| ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:73:11: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | printf("%d\n",bfs(start,end));
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:73:11: warning: 'start' 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |