Submission #1040217

#TimeUsernameProblemLanguageResultExecution timeMemory
1040217dpsaveslivesJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
1097 ms66132 KiB
#include <bits/stdc++.h> #define f first #define s second #define ll long long using namespace std; const int MAXN = 3e4+10; vector<pair<int,ll>> adj[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N,M; cin >> N >> M; vector<pair<int,int>> doges(M); for(int i = 0;i<M;++i){ cin >> doges[i].f >> doges[i].s; } for(int i = 0;i<M;++i){ for(int j = i+1;j<M;++j){ if(doges[j].f == doges[i].f){ adj[i].push_back({j,0}); adj[j].push_back({i,0}); //cout << i << " " << j << "\n"; //cout << j << " " << i << "\n"; continue; } if((abs(doges[j].f-doges[i].f)) % doges[i].s == 0){ //cout << j << " " << i << "\n"; //j to i adj[j].push_back({i,abs(doges[j].f-doges[i].f)/doges[i].s}); //start from the target (1), the directed edges are directed towards 0 } if((abs(doges[j].f-doges[i].f)) % doges[j].s == 0){ //cout << i << " " << j << "\n"; //i to j adj[i].push_back({j,abs(doges[j].f-doges[i].f)/doges[j].s}); } } } priority_queue<pair<ll,int>> pq; pq.push({0,1}); vector<ll> dist(M,-1); dist[1] = 0; while(!pq.empty()){ int u = pq.top().s; ll cd = pq.top().f; pq.pop(); if(cd != dist[u]) continue; for(auto p : adj[u]){ if(cd+p.s < dist[p.f] || dist[p.f] == -1){ dist[p.f] = cd+p.s; pq.push({dist[p.f],p.f}); } } } cout << dist[0] << "\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...