제출 #582465

#제출 시각아이디문제언어결과실행 시간메모리
582465gg123_peJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
28 ms3744 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,int> ii; #define f(i,a,b) for(int i = a; i < b; i++) const int N = 2005; const ll inf = 1e18 + 10; // B ll n, m, b[N], p[N], d[N]; vector <pair<int,ll>> adj[N]; void dij(int x){ f(i,0,m) d[i] = inf; d[x] = 0; priority_queue <ii, vector <ii>, greater<ii>> q; q.push({0, x}); while(!q.empty()){ ii p = q.top(); q.pop(); ll d_v = p.first, v = p.second; if(d_v != d[v]) continue; for(auto wi: adj[v]){ ll u = wi.first, w = wi.second; if(d[u] > d[v] + w){ d[u] = d[v] + w; q.push({d[u], u}); } } } } int main(){ cin >> n >> m; f(i,0,m){ cin >> b[i] >> p[i]; } f(i,0,m){ f(j,0,m){ ll x = abs(b[i]-b[j]); if(x == 0 or x%p[i]) continue; adj[i].push_back({j, x/p[i]}); } } if(b[0] == b[1]){ cout << "0\n"; return 0; } dij(0); cout << ((d[1] == inf) ? -1 : d[1]) << "\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...