제출 #582497

#제출 시각아이디문제언어결과실행 시간메모리
582497YesPyJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms1620 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define PHB push_back #define fastio ios::sync_with_stdio(false);cin.tie(nullptr); #define ln '\n' #define nwln cout<<ln; #define v(T) vector<T> #define PQ(T) priority_queue<T, v(T), greater<T>> using namespace std; typedef pair<int, int> pi; typedef vector<int> vri; typedef vector<pi> vpi; typedef vector<vpi> vvpi; const int INF = 1001001001; const int MAXN = 30003; int N, M; set<int> B[MAXN]; vri dist; vvpi adj; void dijkstra(int src) { dist.assign(N, INF); dist[src] = 0; PQ(pi) pq; pq.push({0, src}); while(!pq.empty()) { int v = pq.top().ss, d_v = pq.top().ff; pq.pop(); if(d_v != dist[v]) continue; for(pi edge: adj[v]) { int w = edge.ss, u = edge.ff; if(dist[v] + w < dist[u]) { dist[u] = dist[v] + w; pq.push({dist[u], u}); } } } } int main() { fastio cin>>N>>M, adj.resize(N); while(M--) { int b, p; cin>>b>>p; B[b].insert(p); } for(int i=0; i<N; ++i) { for(int p: B[i]) { int pos = i+p, cost = 1; while(pos < N) { adj[i].PHB({pos, cost}); if(B[pos].count(p)) break; ++cost, pos += p; } pos = i-p, cost = 1; while(pos >= 0) { adj[i].PHB({pos, cost}); if(B[pos].count(p)) break; ++cost, pos -= p; } } } dijkstra(0); if(dist[1] == INF) cout<<-1; else cout<<dist[1]; nwln 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...