제출 #107900

#제출 시각아이디문제언어결과실행 시간메모리
107900dfistricJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
4 ms1152 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define ll long long using namespace std; const int MAXN = 30010; ll B[MAXN], P[MAXN]; int n, m; vector <pair <int, ll> > ve[MAXN]; set <pair <ll, int> > se; ll dist[MAXN]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; REP(i, m) cin >> B[i] >> P[i]; REP(i, m) { REP(j, m) { if (i == j) continue; if (abs(B[i] - B[j]) % P[i] == 0) ve[i].push_back({j, abs(B[i] - B[j]) / P[i]}); } } FOR(i, 1, n) dist[i] = (1LL << 60); REP(i, n) se.insert({dist[i], i}); while (se.size()) { auto tr = *se.begin(); se.erase(se.begin()); int x = tr.second; ll D = tr.first; if (x == 1) continue; for (auto t : ve[x]) { int y = t.first; ll d = t.second; if (dist[y] > D + d) { se.erase({dist[y], y}); dist[y] = D + d; se.insert({dist[y], y}); } } } cout << dist[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...