이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define MAXN 30005
int n, m, t[MAXN], s, e;
pair<int, int> d[MAXN];
vector<int> p[MAXN];
priority_queue<pair<int, int>> pq;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
FOR(i, 0, m - 1) t[i] = -1;
FOR(i, 0, m - 1){
cin >> d[i].first >> d[i].second;
if(i == 0) {
s = d[i].first;
t[0] = 0;
pq.push({-t[0], 0});
}
if(i == 1) e = d[i].first;
}
while(pq.size()){
int v = pq.top().first;
int pqi = pq.top().second; pq.pop();
if(t[pqi] != -v) continue;
// cout << pqi << " " << -v << endl;
FOR(i, 0, m - 1) if(i != pqi){
if(abs(d[pqi].first - d[i].first) % d[pqi].second == 0 && (t[i] == -1 || t[pqi] + abs(d[pqi].first - d[i].first) / d[pqi].second < t[i])){
t[i] = t[pqi] + abs(d[pqi].first - d[i].first) / d[pqi].second;
pq.push({-t[i], i});
// cout << " => " << i << " " << t[i] << " " << d[pqi].second << endl;
}
}
}
cout << t[1] << endl;
}
# | 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... |