제출 #304602

#제출 시각아이디문제언어결과실행 시간메모리
304602vipghn2003Jakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
2 ms2560 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair using namespace std; const int N=30005; int n,m,b[N],p[N],d[N]; vector<pii>adj[N]; set<int>have[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m; for(int i=1;i<=m;i++) { cin>>b[i]>>p[i]; b[i]++; have[b[i]].insert(p[i]); } for(int i=1;i<=m;i++) { int cur=b[i]; int cnt=0; while(cur+p[i]<=n) { cnt++; cur+=p[i]; adj[b[i]].push_back(mp(cur,cnt)); if(have[cur].find(p[i])!=have[cur].end()) break; } cur=b[i]; cnt=0; while(cur-p[i]>=1) { cnt++; cur-=p[i]; adj[b[i]].push_back(mp(cur,cnt)); if(have[cur].find(p[i])!=have[cur].end()) break; } } memset(d,-1,sizeof d); d[1]=0; priority_queue<pii,vector<pii>,greater<pii>>pq; pq.push(mp(0,1)); while(!pq.empty()) { auto u=pq.top(); pq.pop(); if(u.fi!=d[u.se]) continue; for(auto&v:adj[u.se]) { if(d[v.fi]==-1||d[v.fi]>u.fi+v.se) { d[v.fi]=u.fi+v.se; pq.push(mp(d[v.fi],v.fi)); } } } cout<<d[2]; }
#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...