제출 #884549

#제출 시각아이디문제언어결과실행 시간메모리
884549OAleksaJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define int long long const int N = 2010; const int M = 30010; set<pair<int, int>> g[N]; int n, m, a[M], b[M], d[N]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n >> m; for (int i = 1;i <= n;i++) d[i] = 1e9; for (int i = 1;i <= m;i++) { cin >> a[i] >> b[i]; ++a[i]; } for (int i = 1;i <= m;i++) { for (int j = a[i] + b[i], k = 1;j <= n;j += b[i],k++) g[a[i]].insert({j, k}); for (int j = a[i] - b[i], k = 1;j >= 1;j -= b[i],k++) g[a[i]].insert({j, k}); } priority_queue<pair<int, int>> pq; pq.push({0, 1}); d[1] = 0; while (!pq.empty()) { auto v = pq.top().s; pq.pop(); for (auto u : g[v]) { if (d[u.f] <= d[v] + u.s) continue; d[u.f] = d[v] + u.s; pq.push({-d[u.f], u.f}); } } if (d[2] >= 1e9) cout << -1; else cout << d[2]; } 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...