제출 #462351

#제출 시각아이디문제언어결과실행 시간메모리
462351prvocisloJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
352 ms262148 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> typedef long long ll; using namespace std; const int inf = 1e9 + 5; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<pair<int, int> > > g(n); vector<set<int> > my(n); vector<int> b(m), p(m); for (int i = 0; i < m; i++) { cin >> b[i] >> p[i]; my[b[i]].insert(p[i]); } for (int i = 0; i < m; i++) { for (int j = b[i] + p[i]; j < n; j += p[i]) { g[b[i]].push_back({ j, (j - b[i]) / p[i] }); if (my[j].count(p[i])) break; } for (int j = b[i] - p[i]; j >= 0; j -= p[i]) { g[b[i]].push_back({ j, (b[i] - j) / p[i] }); if (my[j].count(p[i])) break; } } //cout << "\n"; //for (int i = 0; i < n; i++) for (pair<int, int> j : g[i]) cout << i << " " << j.first << " " << j.second << "\n"; priority_queue<pair<int, int> > pq; pq.push({ 0, b[0] }); vector<int> dist(n, inf); while (!pq.empty()) { int u = pq.top().second, d = -pq.top().first; //cout << u << endl; pq.pop(); if (dist[u] != inf) continue; dist[u] = d; for (pair<int, int> i : g[u]) if (dist[i.first] == inf) { pq.push({ -(d + i.second), i.first }); } } cout << (dist[b[1]] == inf ? -1 : dist[b[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...