#include <bits/stdc++.h>
using namespace std;
vector<int> nbJumps;
vector<vector<int>> jump_count;
int main () {
int nbSky, nbDoge;
cin >> nbSky >> nbDoge;
nbJumps.resize(nbSky, -1);
jump_count.resize(nbSky);
int sx = 0;
int ex = 0;
for (int idDoge = 0; idDoge < nbDoge; idDoge ++) {
int x, p;
cin >> x >> p;
if (idDoge == 0) sx = x;
if (idDoge == 1) ex = x;
jump_count[x].push_back(p);
}
set<pair<int, int>> mp;
nbJumps [sx] = 0;
mp.insert({ 0, sx });
while (mp.size() != 0) {
pair<int, int> mu = * mp.begin();
mp.erase(mu);
int curx = mu.second;
if (curx == ex) break ;
for (int jump : jump_count[curx]) {
int i = 1;
for (int nx = curx - jump; nx >= 0; nx -= jump) {
if (nbJumps[nx] == -1 || nbJumps[nx] > nbJumps[curx] + i) {
if (nbJumps[nx] != -1)
mp.erase({ nbJumps[nx], nx });
nbJumps[nx] = nbJumps[curx] + i;
mp.insert({ nbJumps[nx], nx });
}
i ++;
}
i = 1;
for (int nx = curx + jump; nx < nbSky; nx += jump) {
if (nbJumps[nx] == -1 || nbJumps[nx] > nbJumps[curx] + i) {
if (nbJumps[nx] != -1)
mp.erase({ nbJumps[nx], nx });
nbJumps[nx] = nbJumps[curx] + i;
mp.insert({ nbJumps[nx], nx });
}
i ++;
}
}
}
cout << nbJumps[ex];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
7 ms |
524 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
312 KB |
Output is correct |
29 |
Correct |
3 ms |
428 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
428 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
9 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
312 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
428 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
468 KB |
Output is correct |
35 |
Correct |
15 ms |
712 KB |
Output is correct |
36 |
Correct |
4 ms |
440 KB |
Output is correct |
37 |
Correct |
14 ms |
724 KB |
Output is correct |
38 |
Correct |
19 ms |
912 KB |
Output is correct |
39 |
Correct |
14 ms |
884 KB |
Output is correct |
40 |
Correct |
14 ms |
852 KB |
Output is correct |
41 |
Correct |
16 ms |
908 KB |
Output is correct |
42 |
Correct |
12 ms |
724 KB |
Output is correct |
43 |
Correct |
13 ms |
808 KB |
Output is correct |
44 |
Correct |
86 ms |
796 KB |
Output is correct |
45 |
Correct |
17 ms |
736 KB |
Output is correct |
46 |
Correct |
20 ms |
820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
312 KB |
Output is correct |
14 |
Correct |
2 ms |
308 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
10 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
296 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
308 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
4 ms |
428 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
432 KB |
Output is correct |
33 |
Correct |
5 ms |
468 KB |
Output is correct |
34 |
Correct |
4 ms |
468 KB |
Output is correct |
35 |
Correct |
13 ms |
724 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
11 ms |
724 KB |
Output is correct |
38 |
Correct |
16 ms |
840 KB |
Output is correct |
39 |
Correct |
13 ms |
872 KB |
Output is correct |
40 |
Correct |
15 ms |
852 KB |
Output is correct |
41 |
Correct |
16 ms |
820 KB |
Output is correct |
42 |
Correct |
12 ms |
792 KB |
Output is correct |
43 |
Correct |
12 ms |
732 KB |
Output is correct |
44 |
Correct |
76 ms |
724 KB |
Output is correct |
45 |
Correct |
16 ms |
832 KB |
Output is correct |
46 |
Correct |
15 ms |
804 KB |
Output is correct |
47 |
Correct |
31 ms |
1740 KB |
Output is correct |
48 |
Correct |
19 ms |
1604 KB |
Output is correct |
49 |
Correct |
15 ms |
1596 KB |
Output is correct |
50 |
Correct |
15 ms |
1492 KB |
Output is correct |
51 |
Correct |
55 ms |
3348 KB |
Output is correct |
52 |
Correct |
51 ms |
3160 KB |
Output is correct |
53 |
Correct |
22 ms |
2748 KB |
Output is correct |
54 |
Correct |
4 ms |
1748 KB |
Output is correct |
55 |
Correct |
6 ms |
1748 KB |
Output is correct |
56 |
Execution timed out |
1008 ms |
3644 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |