제출 #935426

#제출 시각아이디문제언어결과실행 시간메모리
935426tamir1Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
1060 ms135212 KiB
#include<bits/stdc++.h> #define ll long long #define ff first #define ss second using namespace std; ll n,m,i,j,dist[30005],b,p,x,y,R; vector<ll> v[30005]; bitset<30005> vis; priority_queue<pair<ll,ll>> q; int main(){ cin >> n >> m; for(i=0;i<m;i++){ cin >> b >> p; v[b].push_back(p); if(i==0) q.push({0,b}); if(i==1) R=b; } while(!q.empty()){ x=q.top().ss; y=q.top().ff; q.pop(); if(vis[x]) continue; dist[x]=-y; vis[x]=1; for(ll i:v[x]){ p=0; for(b=x+i;b<n;b+=i){ p++; if(!vis[b]) q.push({y-p,b}); } p=0; for(b=x-i;b>=0;b-=i){ p++; if(!vis[b]) q.push({y-p,b}); } } } if(vis[R]) cout << dist[R]; else cout << -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...