이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N = 3e4+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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |