제출 #299442

#제출 시각아이디문제언어결과실행 시간메모리
299442FlashGamezzzJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1062 ms5368 KiB
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <unordered_set> #include <unordered_map> using namespace std; bool done[30000] = {}; int n, m, d0, d1, ans = -1; unordered_set<int> doges[30000]; unordered_map<int, int> dists; 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].insert(b); } for (int i = 0; i < n; i++){ dists.insert(make_pair(i, 30001)); } dists[d0] = 0; while (true){ int i = -1, md = 30001; for (unordered_map<int, int>::iterator it = dists.begin(); it != dists.end(); it++){ if (it->second < md){ md = it->second; i = it->first; } } if (i == -1){ break; } if (i == d1){ ans = dists[i]; break; } for (int p : doges[i]){ for (long ni = i % p; ni < n; ni+=p){ if (!done[ni] && dists[ni] > dists[i] + abs((i-ni)/p)){ dists[ni] = dists[i] + abs((i-ni)/p); } } } dists.erase(i); 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...