Submission #170846

#TimeUsernameProblemLanguageResultExecution timeMemory
170846NightmarJakarta Skyscrapers (APIO15_skyscraper)C++17
10 / 100
2 ms416 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <iomanip> #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define ppb pop_back #define ft first #define sd second #define read freopen("input.txt", "r", stdin) #define write freopen("output.txt", "w", stdout) #define files read; write using namespace std; typedef long long ll; typedef pair<int, int> pii; const int Z = (int)2e3 + 228; const int N = (int)3e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)1e9 + 7; const ll LLINF = (ll)1e15 + 228; int main() { SWS; //files; int n, m; cin >> n >> m; vector<pii> v; for (int i = 0; i < m; i++) { int b, p; cin >> b >> p; v.pb({b, p}); } set<pii> Q; Q.insert({0, 0}); vector<int> dist(n, INF); dist[0] = 0; while (!Q.empty()) { int ind = Q.begin()->sd; int now = Q.begin()->ft; Q.erase(Q.begin()); for (int i = 0; i < m; i++) if (abs(v[i].ft - v[ind].ft) % v[ind].sd == 0) { int steps = abs(v[i].ft - v[ind].ft) / v[ind].sd; if (now + steps < dist[v[i].ft]) { if (Q.find({dist[v[i].ft], i}) != Q.end()) Q.erase(Q.find({dist[v[i].ft], i})); dist[v[i].ft] = now + steps; Q.insert({dist[v[i].ft], i}); } } } if (dist[v[1].ft] != INF) cout << dist[v[1].ft]; else cout << -1; 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...