#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 3e4+10, M = 1e9+7;
int n, m, b[mxN], p[mxN], dis[mxN];
vector<ar<int, 2>> adj[mxN];
set<ar<int, 2>> s;
void dijkstra(){
priority_queue<ar<int, 2>, vector<ar<int, 2>>, greater<ar<int, 2>>> pq;
memset(dis, 0x3f, sizeof(dis));
pq.push({dis[b[0]] = 0, b[0]});
while(pq.size()){
ar<int, 2> cur = pq.top();
pq.pop();
int v = cur[1];
for(ar<int, 2> u : adj[v]){
if(dis[u[0]] > dis[v] + u[1]){
dis[u[0]] = dis[v] + u[1];
pq.push({dis[u[0]], u[0]});
}
}
}
}
int main(){
cin >> n >> m;
for(int i = 0; i<m; ++i){
cin >> b[i] >> p[i];
s.insert({b[i], p[i]});
}
for(auto v : s){
for(int h = v[0]+v[1]; h<n; h+=v[1]){
adj[v[0]].push_back({h, (h-v[0])/v[1]});
}
for(int h = v[0]-v[1]; h>=0; h-=v[1]){
adj[v[0]].push_back({h, (v[0]-h)/v[1]});
}
}
dijkstra();
cout << (dis[b[1]] >= 1e9?-1:dis[b[1]]) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1128 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1132 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
2 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1228 KB |
Output is correct |
12 |
Correct |
2 ms |
1144 KB |
Output is correct |
13 |
Correct |
2 ms |
1228 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
3 ms |
1228 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
2 ms |
1228 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1228 KB |
Output is correct |
16 |
Correct |
1 ms |
1228 KB |
Output is correct |
17 |
Correct |
3 ms |
1396 KB |
Output is correct |
18 |
Correct |
2 ms |
1264 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
64 ms |
33308 KB |
Output is correct |
21 |
Correct |
2 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
1228 KB |
Output is correct |
23 |
Correct |
2 ms |
1228 KB |
Output is correct |
24 |
Correct |
3 ms |
1356 KB |
Output is correct |
25 |
Correct |
3 ms |
1356 KB |
Output is correct |
26 |
Correct |
4 ms |
1228 KB |
Output is correct |
27 |
Correct |
2 ms |
1128 KB |
Output is correct |
28 |
Correct |
3 ms |
1484 KB |
Output is correct |
29 |
Correct |
4 ms |
1892 KB |
Output is correct |
30 |
Correct |
2 ms |
1356 KB |
Output is correct |
31 |
Correct |
3 ms |
1612 KB |
Output is correct |
32 |
Correct |
2 ms |
1484 KB |
Output is correct |
33 |
Correct |
7 ms |
2636 KB |
Output is correct |
34 |
Correct |
8 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1304 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
2 ms |
1228 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1228 KB |
Output is correct |
16 |
Correct |
2 ms |
1228 KB |
Output is correct |
17 |
Correct |
3 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
1228 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
63 ms |
33296 KB |
Output is correct |
21 |
Correct |
2 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
1228 KB |
Output is correct |
23 |
Correct |
2 ms |
1268 KB |
Output is correct |
24 |
Correct |
3 ms |
1356 KB |
Output is correct |
25 |
Correct |
3 ms |
1356 KB |
Output is correct |
26 |
Correct |
2 ms |
1228 KB |
Output is correct |
27 |
Correct |
2 ms |
1228 KB |
Output is correct |
28 |
Correct |
3 ms |
1484 KB |
Output is correct |
29 |
Correct |
4 ms |
1996 KB |
Output is correct |
30 |
Correct |
2 ms |
1356 KB |
Output is correct |
31 |
Correct |
3 ms |
1612 KB |
Output is correct |
32 |
Correct |
2 ms |
1480 KB |
Output is correct |
33 |
Correct |
7 ms |
2636 KB |
Output is correct |
34 |
Correct |
8 ms |
2728 KB |
Output is correct |
35 |
Correct |
32 ms |
4344 KB |
Output is correct |
36 |
Correct |
5 ms |
1612 KB |
Output is correct |
37 |
Correct |
23 ms |
5440 KB |
Output is correct |
38 |
Correct |
31 ms |
5412 KB |
Output is correct |
39 |
Correct |
32 ms |
5572 KB |
Output is correct |
40 |
Correct |
32 ms |
5532 KB |
Output is correct |
41 |
Correct |
33 ms |
5316 KB |
Output is correct |
42 |
Correct |
15 ms |
1716 KB |
Output is correct |
43 |
Correct |
15 ms |
1624 KB |
Output is correct |
44 |
Correct |
78 ms |
33736 KB |
Output is correct |
45 |
Correct |
35 ms |
7348 KB |
Output is correct |
46 |
Correct |
39 ms |
7392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1148 KB |
Output is correct |
3 |
Correct |
1 ms |
1112 KB |
Output is correct |
4 |
Correct |
1 ms |
1112 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1112 KB |
Output is correct |
7 |
Correct |
1 ms |
1112 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
2 ms |
1240 KB |
Output is correct |
12 |
Correct |
2 ms |
1112 KB |
Output is correct |
13 |
Correct |
2 ms |
1240 KB |
Output is correct |
14 |
Correct |
2 ms |
1240 KB |
Output is correct |
15 |
Correct |
3 ms |
1240 KB |
Output is correct |
16 |
Correct |
1 ms |
1240 KB |
Output is correct |
17 |
Correct |
3 ms |
1496 KB |
Output is correct |
18 |
Correct |
2 ms |
1240 KB |
Output is correct |
19 |
Correct |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
66 ms |
33332 KB |
Output is correct |
21 |
Correct |
2 ms |
1112 KB |
Output is correct |
22 |
Correct |
2 ms |
1228 KB |
Output is correct |
23 |
Correct |
2 ms |
1228 KB |
Output is correct |
24 |
Correct |
3 ms |
1356 KB |
Output is correct |
25 |
Correct |
3 ms |
1356 KB |
Output is correct |
26 |
Correct |
3 ms |
1228 KB |
Output is correct |
27 |
Correct |
2 ms |
1228 KB |
Output is correct |
28 |
Correct |
3 ms |
1368 KB |
Output is correct |
29 |
Correct |
4 ms |
1996 KB |
Output is correct |
30 |
Correct |
2 ms |
1356 KB |
Output is correct |
31 |
Correct |
3 ms |
1612 KB |
Output is correct |
32 |
Correct |
2 ms |
1480 KB |
Output is correct |
33 |
Correct |
7 ms |
2636 KB |
Output is correct |
34 |
Correct |
7 ms |
2636 KB |
Output is correct |
35 |
Correct |
25 ms |
4192 KB |
Output is correct |
36 |
Correct |
5 ms |
1648 KB |
Output is correct |
37 |
Correct |
23 ms |
5464 KB |
Output is correct |
38 |
Correct |
37 ms |
5448 KB |
Output is correct |
39 |
Correct |
33 ms |
5576 KB |
Output is correct |
40 |
Correct |
32 ms |
5488 KB |
Output is correct |
41 |
Correct |
32 ms |
5352 KB |
Output is correct |
42 |
Correct |
17 ms |
1700 KB |
Output is correct |
43 |
Correct |
16 ms |
1612 KB |
Output is correct |
44 |
Correct |
77 ms |
33728 KB |
Output is correct |
45 |
Correct |
36 ms |
7416 KB |
Output is correct |
46 |
Correct |
35 ms |
7364 KB |
Output is correct |
47 |
Correct |
56 ms |
13772 KB |
Output is correct |
48 |
Correct |
27 ms |
4932 KB |
Output is correct |
49 |
Correct |
25 ms |
3876 KB |
Output is correct |
50 |
Correct |
18 ms |
3532 KB |
Output is correct |
51 |
Correct |
58 ms |
7872 KB |
Output is correct |
52 |
Correct |
59 ms |
8068 KB |
Output is correct |
53 |
Correct |
36 ms |
4548 KB |
Output is correct |
54 |
Correct |
3 ms |
1612 KB |
Output is correct |
55 |
Correct |
4 ms |
1992 KB |
Output is correct |
56 |
Runtime error |
511 ms |
262148 KB |
Execution killed with signal 9 |
57 |
Halted |
0 ms |
0 KB |
- |