#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 |
1 |
Correct |
0 ms |
3716 KB |
Output is correct |
2 |
Correct |
0 ms |
3716 KB |
Output is correct |
3 |
Incorrect |
0 ms |
3716 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3716 KB |
Output is correct |
2 |
Correct |
0 ms |
3716 KB |
Output is correct |
3 |
Incorrect |
0 ms |
3716 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3716 KB |
Output is correct |
2 |
Correct |
0 ms |
3716 KB |
Output is correct |
3 |
Incorrect |
0 ms |
3716 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3716 KB |
Output is correct |
2 |
Correct |
0 ms |
3716 KB |
Output is correct |
3 |
Incorrect |
0 ms |
3716 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3716 KB |
Output is correct |
2 |
Correct |
0 ms |
3716 KB |
Output is correct |
3 |
Incorrect |
0 ms |
3716 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |