#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define inf 9223372036854775807
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto& a : x)
ll n,m;
vi b,p,vis,_;
vector<vi> dog;
int main(){
cin >> n >> m; b.assign(m,0); p.assign(m,0);
rep(i,0,m) cin >> b[i] >> p[i];
dog.assign(n,_);
rep(i,0,m) dog[b[i]].push_back(i);
vis.assign(n,0);
priority_queue<ii> pq;
pq.push(make_pair(0,b[0]));
while (!pq.empty()){
ll dist = -pq.top().first, i = pq.top().second; pq.pop();
if (i == b[1]) {
cout << dist << endl;
exit(0);
}
if (vis[i]) continue;
vis[i] = 1;
rep(j,0,sz(dog[i])){
ll px = p[dog[i][j]],cur = i+px,cnt = 1;
while (cur < n) {
if (!vis[cur]) pq.push(make_pair(-dist-cnt,cur));
cur += px; cnt++;
}
cur = i-px, cnt = 1;
while (cur >= 0){
if (!vis[cur]) pq.push(make_pair(-dist-cnt,cur));
cur -= px; cnt++;
}
}
}
cout << -1 << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
392 KB |
Output is correct |
3 |
Correct |
3 ms |
392 KB |
Output is correct |
4 |
Correct |
3 ms |
424 KB |
Output is correct |
5 |
Correct |
2 ms |
424 KB |
Output is correct |
6 |
Correct |
2 ms |
472 KB |
Output is correct |
7 |
Correct |
4 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
528 KB |
Output is correct |
2 |
Correct |
3 ms |
528 KB |
Output is correct |
3 |
Correct |
3 ms |
580 KB |
Output is correct |
4 |
Correct |
3 ms |
580 KB |
Output is correct |
5 |
Correct |
3 ms |
580 KB |
Output is correct |
6 |
Correct |
3 ms |
580 KB |
Output is correct |
7 |
Correct |
3 ms |
580 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
4 ms |
620 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
748 KB |
Output is correct |
14 |
Correct |
5 ms |
848 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
848 KB |
Output is correct |
2 |
Correct |
2 ms |
848 KB |
Output is correct |
3 |
Correct |
2 ms |
848 KB |
Output is correct |
4 |
Correct |
3 ms |
848 KB |
Output is correct |
5 |
Correct |
3 ms |
848 KB |
Output is correct |
6 |
Correct |
3 ms |
848 KB |
Output is correct |
7 |
Correct |
2 ms |
848 KB |
Output is correct |
8 |
Correct |
3 ms |
848 KB |
Output is correct |
9 |
Correct |
2 ms |
848 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
11 |
Correct |
4 ms |
848 KB |
Output is correct |
12 |
Correct |
5 ms |
848 KB |
Output is correct |
13 |
Correct |
6 ms |
848 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
5 ms |
848 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
6 ms |
1020 KB |
Output is correct |
18 |
Correct |
4 ms |
1020 KB |
Output is correct |
19 |
Correct |
4 ms |
1020 KB |
Output is correct |
20 |
Correct |
755 ms |
17364 KB |
Output is correct |
21 |
Correct |
4 ms |
17364 KB |
Output is correct |
22 |
Correct |
4 ms |
17364 KB |
Output is correct |
23 |
Correct |
4 ms |
17364 KB |
Output is correct |
24 |
Correct |
7 ms |
17364 KB |
Output is correct |
25 |
Correct |
4 ms |
17364 KB |
Output is correct |
26 |
Correct |
6 ms |
17364 KB |
Output is correct |
27 |
Correct |
5 ms |
17364 KB |
Output is correct |
28 |
Correct |
6 ms |
17364 KB |
Output is correct |
29 |
Correct |
17 ms |
17364 KB |
Output is correct |
30 |
Correct |
5 ms |
17364 KB |
Output is correct |
31 |
Correct |
10 ms |
17364 KB |
Output is correct |
32 |
Correct |
4 ms |
17364 KB |
Output is correct |
33 |
Correct |
39 ms |
17364 KB |
Output is correct |
34 |
Correct |
21 ms |
17364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
17364 KB |
Output is correct |
2 |
Correct |
3 ms |
17364 KB |
Output is correct |
3 |
Correct |
3 ms |
17364 KB |
Output is correct |
4 |
Correct |
3 ms |
17364 KB |
Output is correct |
5 |
Correct |
3 ms |
17364 KB |
Output is correct |
6 |
Correct |
2 ms |
17364 KB |
Output is correct |
7 |
Correct |
3 ms |
17364 KB |
Output is correct |
8 |
Correct |
2 ms |
17364 KB |
Output is correct |
9 |
Correct |
2 ms |
17364 KB |
Output is correct |
10 |
Correct |
3 ms |
17364 KB |
Output is correct |
11 |
Correct |
4 ms |
17364 KB |
Output is correct |
12 |
Correct |
4 ms |
17364 KB |
Output is correct |
13 |
Correct |
5 ms |
17364 KB |
Output is correct |
14 |
Correct |
4 ms |
17364 KB |
Output is correct |
15 |
Correct |
4 ms |
17364 KB |
Output is correct |
16 |
Correct |
3 ms |
17364 KB |
Output is correct |
17 |
Correct |
6 ms |
17364 KB |
Output is correct |
18 |
Correct |
3 ms |
17364 KB |
Output is correct |
19 |
Correct |
2 ms |
17364 KB |
Output is correct |
20 |
Correct |
635 ms |
17364 KB |
Output is correct |
21 |
Correct |
3 ms |
17364 KB |
Output is correct |
22 |
Correct |
3 ms |
17364 KB |
Output is correct |
23 |
Correct |
4 ms |
17364 KB |
Output is correct |
24 |
Correct |
4 ms |
17364 KB |
Output is correct |
25 |
Correct |
4 ms |
17364 KB |
Output is correct |
26 |
Correct |
5 ms |
17364 KB |
Output is correct |
27 |
Correct |
4 ms |
17364 KB |
Output is correct |
28 |
Correct |
4 ms |
17364 KB |
Output is correct |
29 |
Correct |
17 ms |
17364 KB |
Output is correct |
30 |
Correct |
6 ms |
17364 KB |
Output is correct |
31 |
Correct |
7 ms |
17364 KB |
Output is correct |
32 |
Correct |
7 ms |
17364 KB |
Output is correct |
33 |
Correct |
30 ms |
17364 KB |
Output is correct |
34 |
Correct |
20 ms |
17364 KB |
Output is correct |
35 |
Correct |
30 ms |
17364 KB |
Output is correct |
36 |
Correct |
6 ms |
17364 KB |
Output is correct |
37 |
Correct |
23 ms |
17364 KB |
Output is correct |
38 |
Correct |
36 ms |
17364 KB |
Output is correct |
39 |
Correct |
24 ms |
17364 KB |
Output is correct |
40 |
Correct |
36 ms |
17364 KB |
Output is correct |
41 |
Correct |
37 ms |
17364 KB |
Output is correct |
42 |
Correct |
21 ms |
17364 KB |
Output is correct |
43 |
Correct |
27 ms |
17364 KB |
Output is correct |
44 |
Correct |
806 ms |
18132 KB |
Output is correct |
45 |
Correct |
249 ms |
18132 KB |
Output is correct |
46 |
Correct |
125 ms |
18132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
18132 KB |
Output is correct |
2 |
Correct |
2 ms |
18132 KB |
Output is correct |
3 |
Correct |
4 ms |
18132 KB |
Output is correct |
4 |
Correct |
3 ms |
18132 KB |
Output is correct |
5 |
Correct |
3 ms |
18132 KB |
Output is correct |
6 |
Correct |
3 ms |
18132 KB |
Output is correct |
7 |
Correct |
2 ms |
18132 KB |
Output is correct |
8 |
Correct |
3 ms |
18132 KB |
Output is correct |
9 |
Correct |
4 ms |
18132 KB |
Output is correct |
10 |
Correct |
3 ms |
18132 KB |
Output is correct |
11 |
Correct |
5 ms |
18132 KB |
Output is correct |
12 |
Correct |
4 ms |
18132 KB |
Output is correct |
13 |
Correct |
6 ms |
18132 KB |
Output is correct |
14 |
Correct |
4 ms |
18132 KB |
Output is correct |
15 |
Correct |
4 ms |
18132 KB |
Output is correct |
16 |
Correct |
4 ms |
18132 KB |
Output is correct |
17 |
Correct |
5 ms |
18132 KB |
Output is correct |
18 |
Correct |
4 ms |
18132 KB |
Output is correct |
19 |
Correct |
3 ms |
18132 KB |
Output is correct |
20 |
Correct |
625 ms |
18132 KB |
Output is correct |
21 |
Correct |
3 ms |
18132 KB |
Output is correct |
22 |
Correct |
3 ms |
18132 KB |
Output is correct |
23 |
Correct |
4 ms |
18132 KB |
Output is correct |
24 |
Correct |
5 ms |
18132 KB |
Output is correct |
25 |
Correct |
3 ms |
18132 KB |
Output is correct |
26 |
Correct |
5 ms |
18132 KB |
Output is correct |
27 |
Correct |
5 ms |
18132 KB |
Output is correct |
28 |
Correct |
5 ms |
18132 KB |
Output is correct |
29 |
Correct |
17 ms |
18132 KB |
Output is correct |
30 |
Correct |
6 ms |
18132 KB |
Output is correct |
31 |
Correct |
8 ms |
18132 KB |
Output is correct |
32 |
Correct |
7 ms |
18132 KB |
Output is correct |
33 |
Correct |
35 ms |
18132 KB |
Output is correct |
34 |
Correct |
21 ms |
18132 KB |
Output is correct |
35 |
Correct |
26 ms |
18132 KB |
Output is correct |
36 |
Correct |
7 ms |
18132 KB |
Output is correct |
37 |
Correct |
40 ms |
18132 KB |
Output is correct |
38 |
Correct |
30 ms |
18132 KB |
Output is correct |
39 |
Correct |
24 ms |
18132 KB |
Output is correct |
40 |
Correct |
35 ms |
18132 KB |
Output is correct |
41 |
Correct |
34 ms |
18132 KB |
Output is correct |
42 |
Correct |
31 ms |
18132 KB |
Output is correct |
43 |
Correct |
20 ms |
18132 KB |
Output is correct |
44 |
Correct |
791 ms |
18132 KB |
Output is correct |
45 |
Correct |
192 ms |
18132 KB |
Output is correct |
46 |
Correct |
129 ms |
18132 KB |
Output is correct |
47 |
Correct |
31 ms |
18132 KB |
Output is correct |
48 |
Correct |
22 ms |
18132 KB |
Output is correct |
49 |
Correct |
34 ms |
18132 KB |
Output is correct |
50 |
Correct |
20 ms |
18132 KB |
Output is correct |
51 |
Correct |
74 ms |
18132 KB |
Output is correct |
52 |
Correct |
70 ms |
18132 KB |
Output is correct |
53 |
Correct |
38 ms |
18132 KB |
Output is correct |
54 |
Correct |
9 ms |
18132 KB |
Output is correct |
55 |
Correct |
7 ms |
18132 KB |
Output is correct |
56 |
Execution timed out |
1046 ms |
263168 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |