제출 #208784

#제출 시각아이디문제언어결과실행 시간메모리
208784YJUJakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
986 ms262148 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll MOD=1e9+7; const ll N=3e4+5; const ll INF=(1LL<<60); const ld pi=3.14159265359; #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(a) (ll)a.size() ll n,m,b[N],p[N],x,y,dis[N]; vector<ll> P[N],tmp; vector<pll> v[N]; vector<vector<ll> > lis; priority_queue<pll,vector<pll>,greater<pll> > pq; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; REP(i,m){ cin>>b[i]>>p[i]; P[p[i]].pb(b[i]); } for(ll step=1;step<N;++step){ if(!SZ(P[step]))continue; lis.clear();lis.resize(step); tmp.clear(); for(auto i:P[step]){ lis[i%step].pb(i); tmp.pb(i%step); } sort(tmp.begin(),tmp.end()); tmp.resize(unique(tmp.begin(),tmp.end())-tmp.begin()); for(auto i:tmp){ sort(lis[i].begin(),lis[i].end()); for(ll j=1;j<SZ(lis[i]);++j){ x=lis[i][j-1],y=lis[i][j]; for(ll ii=x;ii<=y;ii+=step){ v[x].pb(mp(ii,(ii-x)/step)); v[y].pb(mp(ii,(y-ii)/step)); } } for(ll ii=lis[i].back();ii<N;ii+=step)x=lis[i].back(),v[x].pb(mp(ii,(ii-x)/step)); for(ll ii=lis[i][0];ii>=0;ii-=step)x=lis[i][0],v[x].pb(mp(ii,(x-ii)/step)); } } REP(i,N)dis[i]=INF; pq.push(mp(0,b[0])); while(SZ(pq)){ x=pq.top().Y;y=pq.top().X;pq.pop(); if(dis[x]<=y)continue; dis[x]=y; for(auto j:v[x])if(dis[j.X]>dis[x]+j.Y)pq.push(mp(dis[x]+j.Y,j.X)); } cout<<(dis[b[1]]==INF?-1:dis[b[1]])<<"\n"; return 0; }
#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...