제출 #1125308

#제출 시각아이디문제언어결과실행 시간메모리
1125308njoopJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
354 ms327680 KiB
#include <bits/stdc++.h> #define int short #define tiii tuple<int, int, int> using namespace std; int MXN = 30000; int n, m, dis[30001][175], b, p, d=174, st, en, cnt, cd, cb, cp, nd, nb, np;; vector<tiii> g[30001][175]; priority_queue<tiii, vector<tiii>, greater<tiii>> pq; void dijkstra() { pq.push({0, st, 0}); while(pq.size()) { cd = get<0>(pq.top()); cb = get<1>(pq.top()); cp = get<2>(pq.top()); pq.pop(); if(cd > dis[cb][cp]) continue; for(auto i: g[cb][cp]) { nd = cd+get<2>(i); nb = get<0>(i); np = get<1>(i); if(nd < dis[nb][np]) { dis[nb][np] = nd; pq.push({nd, nb, np}); } } if(cp != 0 && cp != d && cb-cp >= 0) { if(cd+1 < dis[cb-cp][cp]) { dis[cb-cp][cp] = cd+1; pq.push({cd+1, cb-cp, cp}); } } if(cp != 0 && cp != d && cb+cp < n) { if(cd+1 < dis[cb+cp][cp]) { dis[cb+cp][cp] = cd+1; pq.push({cd+1, cb+cp, cp}); } } if(cp != 0 && cd < dis[cb][0]) { dis[cb][0] = cd; pq.push({cd, cb, 0}); } } } signed main() { cin >> n >> m; for(int i=0; i<30001; i++) { for(int j=0; j<175; j++) { dis[i][j] = 32700; } } for(int i=0; i<m; i++) { cin >> b >> p; if(i == 0) st = b; if(i == 1) en = b; if(p >= sqrt(MXN)) { cnt = 0; for(int j=b; j<n; j+=p) { g[b][d].push_back({j, 0, cnt}); cnt++; } cnt = 1; for(int j=b-p; j>=0; j-=p) { g[b][d].push_back({j, 0, cnt}); cnt++; } g[b][0].push_back({b, d, 0}); } else { g[b][0].push_back({b, p, 0}); } } dijkstra(); if(dis[en][0] == 32700) cout << -1; else cout << dis[en][0]; 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...