#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
int d[30300][2];
vector<int> v[30300];
int p[30300];
int e[30303];
int main() {
int n,m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> d[i][0] >> d[i][1];
int x = d[i][0];
int y = d[i][1];
v[x].push_back(y);
}
priority_queue<pair<int,int>> q;
for (int i = 0; i < 30300; i++)
e[i] = 1e9;
q.push({0,d[0][0]});
e[d[0][0]] = 0;
while(!q.empty()) {
int s = q.top().s;
int x = -q.top().f;
q.pop();
if (x > e[s]) continue;
if (s == d[1][0]) {
cout << x << "\n";
return 0;
}
for (int u : v[s]) {
int it = 1;
for (int i = s-u; i >= 0; i -= u) {
if (e[s] + it < e[i]) {
// cout << s << " -> " << i << " " << it <<"\n";
e[i] = it + e[s];
q.push({-e[i],i});
}
++it;
}
it = 1;
for (int i = s+u; i < n; i += u) {
if (e[s] + it < e[i]) {
// cout << s << " -> " << i << " " << it << "\n";
e[i] = it + e[s];
q.push({-e[i],i});
}
++it;
}
}
}
cout << -1 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 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 |
# |
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 |
2 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 |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
3 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
2 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 |
2 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 |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
4 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
3 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
3 ms |
1100 KB |
Output is correct |
20 |
Correct |
6 ms |
1244 KB |
Output is correct |
21 |
Correct |
2 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1104 KB |
Output is correct |
23 |
Correct |
2 ms |
1100 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
2 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1100 KB |
Output is correct |
27 |
Correct |
3 ms |
1172 KB |
Output is correct |
28 |
Correct |
3 ms |
1100 KB |
Output is correct |
29 |
Correct |
2 ms |
1232 KB |
Output is correct |
30 |
Correct |
2 ms |
1228 KB |
Output is correct |
31 |
Correct |
2 ms |
1228 KB |
Output is correct |
32 |
Correct |
2 ms |
1228 KB |
Output is correct |
33 |
Correct |
3 ms |
1228 KB |
Output is correct |
34 |
Correct |
3 ms |
1356 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 |
2 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
2 ms |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
2 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1180 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1104 KB |
Output is correct |
20 |
Correct |
6 ms |
1248 KB |
Output is correct |
21 |
Correct |
2 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
2 ms |
1176 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
2 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1100 KB |
Output is correct |
27 |
Correct |
2 ms |
1100 KB |
Output is correct |
28 |
Correct |
3 ms |
1100 KB |
Output is correct |
29 |
Correct |
3 ms |
1228 KB |
Output is correct |
30 |
Correct |
2 ms |
1228 KB |
Output is correct |
31 |
Correct |
2 ms |
1228 KB |
Output is correct |
32 |
Correct |
2 ms |
1228 KB |
Output is correct |
33 |
Correct |
3 ms |
1228 KB |
Output is correct |
34 |
Correct |
3 ms |
1356 KB |
Output is correct |
35 |
Correct |
15 ms |
1476 KB |
Output is correct |
36 |
Correct |
5 ms |
1224 KB |
Output is correct |
37 |
Correct |
12 ms |
1484 KB |
Output is correct |
38 |
Correct |
23 ms |
1868 KB |
Output is correct |
39 |
Correct |
17 ms |
1868 KB |
Output is correct |
40 |
Correct |
17 ms |
1632 KB |
Output is correct |
41 |
Correct |
18 ms |
1608 KB |
Output is correct |
42 |
Correct |
21 ms |
1604 KB |
Output is correct |
43 |
Correct |
14 ms |
1772 KB |
Output is correct |
44 |
Correct |
81 ms |
1484 KB |
Output is correct |
45 |
Correct |
16 ms |
1704 KB |
Output is correct |
46 |
Correct |
17 ms |
1568 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 |
2 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 |
1100 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
2 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
3 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1100 KB |
Output is correct |
20 |
Correct |
6 ms |
1244 KB |
Output is correct |
21 |
Correct |
3 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
1100 KB |
Output is correct |
23 |
Correct |
2 ms |
1100 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
2 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1100 KB |
Output is correct |
27 |
Correct |
3 ms |
1100 KB |
Output is correct |
28 |
Correct |
4 ms |
1100 KB |
Output is correct |
29 |
Correct |
2 ms |
1228 KB |
Output is correct |
30 |
Correct |
3 ms |
1228 KB |
Output is correct |
31 |
Correct |
3 ms |
1228 KB |
Output is correct |
32 |
Correct |
3 ms |
1148 KB |
Output is correct |
33 |
Correct |
4 ms |
1228 KB |
Output is correct |
34 |
Correct |
3 ms |
1356 KB |
Output is correct |
35 |
Correct |
16 ms |
1484 KB |
Output is correct |
36 |
Correct |
4 ms |
1228 KB |
Output is correct |
37 |
Correct |
15 ms |
1604 KB |
Output is correct |
38 |
Correct |
19 ms |
1888 KB |
Output is correct |
39 |
Correct |
19 ms |
1768 KB |
Output is correct |
40 |
Correct |
19 ms |
1652 KB |
Output is correct |
41 |
Correct |
18 ms |
1664 KB |
Output is correct |
42 |
Correct |
14 ms |
1652 KB |
Output is correct |
43 |
Correct |
15 ms |
1612 KB |
Output is correct |
44 |
Correct |
98 ms |
1612 KB |
Output is correct |
45 |
Correct |
22 ms |
1820 KB |
Output is correct |
46 |
Correct |
16 ms |
1740 KB |
Output is correct |
47 |
Correct |
18 ms |
2316 KB |
Output is correct |
48 |
Correct |
16 ms |
1996 KB |
Output is correct |
49 |
Correct |
23 ms |
1860 KB |
Output is correct |
50 |
Correct |
15 ms |
1760 KB |
Output is correct |
51 |
Correct |
37 ms |
3028 KB |
Output is correct |
52 |
Correct |
29 ms |
2516 KB |
Output is correct |
53 |
Correct |
25 ms |
2376 KB |
Output is correct |
54 |
Correct |
2 ms |
1356 KB |
Output is correct |
55 |
Correct |
3 ms |
1356 KB |
Output is correct |
56 |
Correct |
927 ms |
2884 KB |
Output is correct |
57 |
Correct |
5 ms |
2380 KB |
Output is correct |
58 |
Correct |
728 ms |
1832 KB |
Output is correct |
59 |
Correct |
25 ms |
1868 KB |
Output is correct |
60 |
Correct |
22 ms |
1960 KB |
Output is correct |
61 |
Correct |
23 ms |
1936 KB |
Output is correct |
62 |
Correct |
35 ms |
2580 KB |
Output is correct |
63 |
Correct |
48 ms |
2892 KB |
Output is correct |
64 |
Correct |
32 ms |
2964 KB |
Output is correct |
65 |
Correct |
34 ms |
2944 KB |
Output is correct |
66 |
Correct |
69 ms |
3912 KB |
Output is correct |
67 |
Correct |
39 ms |
3864 KB |
Output is correct |