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;
const int MAX = (3e4)+1, INF = 1e9;
int n, m, bc, sz, d[MAX];
vector<int> a[MAX];
vector<pair<int,int> > g[MAX];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
bc = sqrt(n), sz = n/bc;
for(int i = 0, pos, len; i < m; i++) {
cin >> pos >> len;
a[pos].push_back(len);
}
for(int i = 0; i < n; i++) for(int len: a[i]) {
for(int j = i-len; j >= 0; j -= len) g[i].emplace_back(j, (i-j)/len);
for(int j = i+len; j < n; j += len) g[i].emplace_back(j, (j-i)/len);
}
fill(d+1, d+n, INF);
priority_queue<pair<int,int> > pq;
pq.emplace(0, 0);
while(!pq.empty()) {
int u = pq.top().second;
pq.pop();
for(auto p: g[u]) {
int v, w; tie(v, w) = p;
if(d[u] + w < d[v]) {
d[v] = d[u] + w;
pq.emplace(-d[v], v);
}
}
}
cout << d[1];
}
# | 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... |