제출 #299814

#제출 시각아이디문제언어결과실행 시간메모리
299814FlashGamezzzJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
952 ms3320 KiB
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <queue> #include <set> #include <map> #include <unordered_set> using namespace std; bool done[30001] = {}; long temp; int n, m, d0, d1, dists[30001] = {}, ans = -1; vector<int> doges[30001]; priority_queue<pair<int, int> > pq; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++){ int a, b; cin >> a >> b; if (i == 0) d0 = a; if (i == 1) d1 = a; doges[a].push_back(b); } for (int i = 0; i < n; i++){ dists[i] = 30001; } pq.push(make_pair(0, d0)); dists[d0] = 0; while (pq.size() > 0){ int i = pq.top().second; pq.pop(); if (done[i]){ continue; } if (i == d1){ ans = dists[i]; break; } for (int p : doges[i]){ for (int j=i+p, add = 1; j<n; j+= p, add++) { temp = dists[i]+add; if (temp < dists[j]) { dists[j] = temp; pq.push(make_pair(-dists[j], j)); } } for (int j=i-p, add = 1; j>= 0; j-= p, add++) { temp = dists[i]+add; if (temp < dists[j]) { dists[j] = temp; pq.push(make_pair(-dists[j], j)); } } } done[i] = true; } cout << ans << endl; }
#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...