제출 #582498

#제출 시각아이디문제언어결과실행 시간메모리
582498NekoRollyJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
115 ms64624 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const int N = 2e3+4; const ll inf = 1e18; int n,m; int pos[N],p[N]; vector<pll> adj[N]; priority_queue<pll, vector<pll>, greater<pll>> d; ll dis[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=1; i<=m; i++) cin >> pos[i] >> p[i]; for (int i=1; i<=m; i++) for (int j=1; j<=m; j++) if (pos[i]%p[i] == pos[j]%p[i]){ // cout << i << " -> " << j << "\n"; adj[i].push_back({j, abs(pos[j]-pos[i])/p[i]}); } d.push({0, 1}); for (int i=2; i<=m; i++) dis[i] = inf; for (; d.size(); ){ auto [w, u] = d.top(); d.pop(); if (w != dis[u]) continue; for (auto [v, we] : adj[u]) if (dis[v] > w + we) d.push({dis[v] = w + we, v}); } cout << (dis[2] == inf ? -1 : dis[2]) << "\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...