이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m,i,j,dist[200005],b[200005],p[200005],x,y;
vector<pair<ll,ll>> v[200005];
bitset<200005> vis;
priority_queue<pair<ll,ll>> q;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(i=0;i<m;i++){
cin >> b[i] >> p[i];
x=b[i]+p[i];
y=0;
while(x<n){
y++;
v[b[i]].push_back({x,y});
x+=p[i];
}
x=b[i]-p[i];
y=0;
while(x>=0){
y++;
v[b[i]].push_back({x,y});
x-=p[i];
}
}
q.push({0,b[0]});
while(!q.empty()){
x=q.top().ss;
y=q.top().ff;
q.pop();
if(vis[x]) continue;
dist[x]=-y;
vis[x]=1;
for(i=0;i<v[x].size();i++){
if(!vis[v[x][i].ff]){
q.push({y-v[x][i].ss,v[x][i].ff});
}
}
}
if(vis[b[1]]) cout << dist[b[1]];
else cout << -1;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:40:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# | 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... |