This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
const int MAXN = 30100;
int n, m;
int b[MAXN], p[MAXN];
vii adj[MAXN];
int d[MAXN];
priority_queue<pii, vii, greater<pii>> q;
bool vis[MAXN];
void dijkstra () {
FOR(i, 0, m-1) d[i] = -1;
d[0] = 0;
q.push({d[0], 0});
while (!q.empty()) {
int v = q.top().s;
q.pop();
if (vis[v]) continue;
vis[v] = true;
for (auto p : adj[v]) {
int w = p.s;
int u = p.f;
if (d[u] == -1 || d[u] > d[v]+w) {
d[u] = d[v]+w;
q.push({d[u], u});
}
}
}
}
int main()
{
FAST_IO;
cin >> n >> m;
FOR(i, 0, m-1) cin >> b[i] >> p[i];
FOR(i, 0, m-1) FOR(j, 0, m-1) {
int d = abs(b[j] - b[i]);
if (d % p[i]) continue;
int x = d / p[i];
adj[i].pb({j, x});
}
dijkstra();
cout << d[1] << "\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... |