이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e4+2;
const int magic=180;
const int inf=1e18+7;
const int LIM=N*magic+2*N;
int b[N],p[N],dis[LIM];
vector<pair<int,int> > adj[LIM];
priority_queue<pair<int,int> > lis;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,i,j,k,l;
cin>>n>>m;
for(i=0;i<m;i++){ //0->m-1
cin>>b[i]>>p[i];
}
//m->m+n-1 la cac nut dai dien
//m+n -> m+n*sqrt(n) la cac nut dai dien cho cac luong van tai
for(i=1;i<=min(magic,n-1);i++){
for(j=0;j<n-i;j++){
k=i*n+j+m;
l=i*n+j+i+m;
adj[k].push_back({l,1});
adj[l].push_back({k,1});
}
for(j=0;j<n;j++){
adj[m+j].push_back({i*n+j+m,0});
}
}
for(i=0;i<m;i++){
if(p[i]>magic){
j=b[i];
k=0;
while(j>=0){
adj[i].push_back({m+j,k});
j-=p[i];
k++;
}
j=b[i];
while(true){
j+=p[i];
k++;
if(j>=n){
break;
}
adj[i].push_back({m+j,k});
}
}
else{
for(j=1;j<=min(n-1,magic);j++){
k=j*n+b[i]+m;
adj[k].push_back({i,0});
}
k=p[i]*n+b[i]+m;
adj[i].push_back({k,0});
}
}
for(i=1;i<=m+magic*n+n;i++){
dis[i]=inf;
}
dis[0]=0;
lis.push({0,0});
while(lis.size()){
j=-lis.top().first;
k=lis.top().second;
lis.pop();
if(dis[k]==j){
for(i=0;i<adj[k].size();i++){
if(dis[adj[k][i].first]>dis[k]+adj[k][i].second){
dis[adj[k][i].first]=dis[k]+adj[k][i].second;
lis.push({-dis[adj[k][i].first],adj[k][i].first});
}
}
}
}
if(dis[1]!=inf){
cout<<dis[1];
}
else{
cout<<-1;
}
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:70:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<adj[k].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... |