제출 #582462

#제출 시각아이디문제언어결과실행 시간메모리
582462gg123_peJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
27 ms2068 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; #define f(i,a,b) for(int i = a; i < b; i++) const int N = 2005, inf = 1e9 + 10; // B int n, m, b[N], p[N], d[N]; vector <pair<int,int>> 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(); int d_v = p.first, v = p.second; if(d_v != d[v]) continue; for(auto wi: adj[v]){ int 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){ int 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...