#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
int N, M, B[30005], P[30005];
vector<pii> adj[30005];
int mindis[30005];
set<int> dog[30005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>N>>M;
for(int i=0;i<M;i++) {
cin>>B[i]>>P[i];
dog[B[i]].insert(-P[i]);
}
for(int i=0;i<N;i++) {
for(int pp:dog[i]) {
int p = -pp;
for(int j=1;i-(j*p)>=0;j++) adj[i].push_back({i-(j*p), j});
for(int j=1;i+(j*p)<N;j++) adj[i].push_back({i+(j*p), j});
}
mindis[i] = 2e9;
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0, B[0]});
mindis[B[0]] = 0;
while(!pq.empty()) {
auto [dis, u] = pq.top();
pq.pop();
if(mindis[u]!=dis) continue;
for(auto [v, w]:adj[u]) {
if(mindis[v]>dis+w) {
mindis[v] = dis+w;
pq.push({mindis[v], v});
}
}
}
if(mindis[B[1]]==2e9) cout<<-1;
else cout<<mindis[B[1]];
}
/*
5 3
0 2
1 1
4 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2900 KB |
Output is correct |
6 |
Correct |
1 ms |
2904 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2704 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2908 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
55 ms |
34932 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2816 KB |
Output is correct |
24 |
Correct |
2 ms |
2888 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2908 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2948 KB |
Output is correct |
32 |
Correct |
2 ms |
2996 KB |
Output is correct |
33 |
Correct |
4 ms |
3984 KB |
Output is correct |
34 |
Correct |
3 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2904 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2700 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2908 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
55 ms |
34856 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2908 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2708 KB |
Output is correct |
28 |
Correct |
1 ms |
2908 KB |
Output is correct |
29 |
Correct |
3 ms |
3216 KB |
Output is correct |
30 |
Correct |
2 ms |
2908 KB |
Output is correct |
31 |
Correct |
2 ms |
2960 KB |
Output is correct |
32 |
Correct |
2 ms |
2908 KB |
Output is correct |
33 |
Correct |
3 ms |
3932 KB |
Output is correct |
34 |
Correct |
4 ms |
3932 KB |
Output is correct |
35 |
Correct |
10 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
3164 KB |
Output is correct |
37 |
Correct |
10 ms |
7000 KB |
Output is correct |
38 |
Correct |
13 ms |
7004 KB |
Output is correct |
39 |
Correct |
12 ms |
7232 KB |
Output is correct |
40 |
Correct |
13 ms |
7144 KB |
Output is correct |
41 |
Correct |
13 ms |
7000 KB |
Output is correct |
42 |
Correct |
4 ms |
3160 KB |
Output is correct |
43 |
Correct |
4 ms |
3164 KB |
Output is correct |
44 |
Correct |
57 ms |
35156 KB |
Output is correct |
45 |
Correct |
15 ms |
8536 KB |
Output is correct |
46 |
Correct |
15 ms |
8536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2904 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2908 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
58 ms |
35148 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2908 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2908 KB |
Output is correct |
29 |
Correct |
3 ms |
3420 KB |
Output is correct |
30 |
Correct |
2 ms |
2996 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
2 ms |
2908 KB |
Output is correct |
33 |
Correct |
3 ms |
3932 KB |
Output is correct |
34 |
Correct |
4 ms |
4000 KB |
Output is correct |
35 |
Correct |
10 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
3164 KB |
Output is correct |
37 |
Correct |
10 ms |
7004 KB |
Output is correct |
38 |
Correct |
12 ms |
7000 KB |
Output is correct |
39 |
Correct |
13 ms |
7092 KB |
Output is correct |
40 |
Correct |
14 ms |
7140 KB |
Output is correct |
41 |
Correct |
12 ms |
7004 KB |
Output is correct |
42 |
Correct |
4 ms |
3164 KB |
Output is correct |
43 |
Correct |
5 ms |
3164 KB |
Output is correct |
44 |
Correct |
59 ms |
35156 KB |
Output is correct |
45 |
Correct |
15 ms |
8536 KB |
Output is correct |
46 |
Correct |
15 ms |
8540 KB |
Output is correct |
47 |
Correct |
28 ms |
15332 KB |
Output is correct |
48 |
Correct |
10 ms |
6360 KB |
Output is correct |
49 |
Correct |
8 ms |
5468 KB |
Output is correct |
50 |
Correct |
9 ms |
4956 KB |
Output is correct |
51 |
Correct |
26 ms |
9164 KB |
Output is correct |
52 |
Correct |
32 ms |
9564 KB |
Output is correct |
53 |
Correct |
17 ms |
6104 KB |
Output is correct |
54 |
Correct |
2 ms |
3164 KB |
Output is correct |
55 |
Correct |
3 ms |
3544 KB |
Output is correct |
56 |
Runtime error |
445 ms |
262144 KB |
Execution killed with signal 9 |
57 |
Halted |
0 ms |
0 KB |
- |