Submission #582847

#TimeUsernameProblemLanguageResultExecution timeMemory
582847Justin1Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
1085 ms81612 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; using pii = pair<int,int>; struct edge{ int v, c; }; int n,m,k,x,y,z; int pos[30005], power[30005]; vector<edge> gph[30005]; int dis[30005]; priority_queue<pii,vector<pii>,greater<pii>> nxt; void dijkstra() { for (int i = 1; i <= m; i++) dis[i] = -1; nxt.push({0,pos[1]}); while (nxt.size()) { auto tmp = nxt.top(); nxt.pop(); if (dis[tmp.s] != -1) continue; dis[tmp.s] = tmp.f; for (auto i : gph[tmp.s]) nxt.push({tmp.f+i.c,i.v}); } cout << dis[pos[2]] << "\n"; } int main() { cin >> m >> n; for (int i = 1; i <= n; i++) cin >> pos[i] >> power[i]; for (int i = 1; i <= n; i++) pos[i]++; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j) continue; if (abs(pos[i]-pos[j]) % power[i] == 0) { gph[pos[i]].push_back({pos[j], abs(pos[i]-pos[j]) / power[i]}); } } } dijkstra(); }
#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...