#include<bits/stdc++.h>
using namespace std;
#define ll int
#define ss second
#define ff first
#define INF 2000000000000000
#define pb push_back
#define edge pair<ll, pair<ll,ll> > // une, number ,power
#define cost first
#define num second.first
#define pwr second.second
ll n,m,l,r,i,j,ii,jj,k,x,y,D[30005][180],s,e;
vector< edge > v[30005][180]; // number , power (powergu oroi bol power = 179)
int main(){
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cin>>n>>m;
for(i=1;i<=m;i++){
cin>>l>>r;
if(i==1) s=l;
if(i==2) e=l;
if(r>140)
for(j=1 ; l+r*j<n || l-r*j>=0 ; j++){
edge a;
a.num=l+r*j;
a.pwr=179;
a.cost=j;
if(a.num<n) v[l][179].pb(a);
a.num=l-r*j;
if(a.num>=0) v[l][179].pb(a);
}
else{
v[l][179].pb({0,{l,r}});
}
}
for(i=1;i<=140;i++)
for(j=0;j<n;j++){
v[j][i].pb({0,{j,179}});
if(j+i<n) v[j][i].pb({1,{j+i,i}});
if(j-i>=0) v[j][i].pb({1,{j-i,i}});
}
priority_queue<edge , vector< edge >, greater< edge > > q;
memset(D,-1,sizeof(D));
q.push({0,{s,179}});
while(!q.empty()){
ll une, nmbr, power;
une=q.top().cost;
nmbr=q.top().num;
power=q.top().pwr;
q.pop();
if(D[nmbr][power]!=-1) continue;
D[nmbr][power]=une;
for(edge no : v[nmbr][power]) if(D[no.num][no.pwr]==-1) q.push({une+no.cost,{no.num,no.pwr}});
}
cout<<D[e][179];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
148252 KB |
Output is correct |
2 |
Correct |
66 ms |
148352 KB |
Output is correct |
3 |
Correct |
66 ms |
148172 KB |
Output is correct |
4 |
Correct |
66 ms |
148244 KB |
Output is correct |
5 |
Correct |
69 ms |
148196 KB |
Output is correct |
6 |
Correct |
66 ms |
148268 KB |
Output is correct |
7 |
Correct |
66 ms |
148220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
148288 KB |
Output is correct |
2 |
Correct |
69 ms |
148180 KB |
Output is correct |
3 |
Correct |
76 ms |
148180 KB |
Output is correct |
4 |
Correct |
66 ms |
148236 KB |
Output is correct |
5 |
Correct |
68 ms |
148260 KB |
Output is correct |
6 |
Correct |
76 ms |
148236 KB |
Output is correct |
7 |
Correct |
66 ms |
148308 KB |
Output is correct |
8 |
Correct |
65 ms |
148360 KB |
Output is correct |
9 |
Correct |
77 ms |
148460 KB |
Output is correct |
10 |
Correct |
70 ms |
148720 KB |
Output is correct |
11 |
Correct |
75 ms |
148808 KB |
Output is correct |
12 |
Correct |
69 ms |
148860 KB |
Output is correct |
13 |
Correct |
70 ms |
148812 KB |
Output is correct |
14 |
Correct |
72 ms |
148812 KB |
Output is correct |
15 |
Correct |
78 ms |
148836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
148272 KB |
Output is correct |
2 |
Correct |
67 ms |
148172 KB |
Output is correct |
3 |
Correct |
66 ms |
148300 KB |
Output is correct |
4 |
Correct |
71 ms |
148188 KB |
Output is correct |
5 |
Correct |
68 ms |
148312 KB |
Output is correct |
6 |
Correct |
70 ms |
148264 KB |
Output is correct |
7 |
Correct |
68 ms |
148308 KB |
Output is correct |
8 |
Correct |
70 ms |
148436 KB |
Output is correct |
9 |
Correct |
71 ms |
148548 KB |
Output is correct |
10 |
Correct |
82 ms |
148688 KB |
Output is correct |
11 |
Correct |
69 ms |
148844 KB |
Output is correct |
12 |
Correct |
69 ms |
148800 KB |
Output is correct |
13 |
Correct |
69 ms |
148820 KB |
Output is correct |
14 |
Correct |
69 ms |
148872 KB |
Output is correct |
15 |
Correct |
70 ms |
148860 KB |
Output is correct |
16 |
Correct |
76 ms |
149448 KB |
Output is correct |
17 |
Correct |
90 ms |
154192 KB |
Output is correct |
18 |
Correct |
106 ms |
163000 KB |
Output is correct |
19 |
Correct |
105 ms |
165116 KB |
Output is correct |
20 |
Correct |
105 ms |
165180 KB |
Output is correct |
21 |
Correct |
90 ms |
151092 KB |
Output is correct |
22 |
Correct |
107 ms |
163292 KB |
Output is correct |
23 |
Correct |
103 ms |
161752 KB |
Output is correct |
24 |
Correct |
107 ms |
164400 KB |
Output is correct |
25 |
Correct |
116 ms |
165196 KB |
Output is correct |
26 |
Correct |
111 ms |
165168 KB |
Output is correct |
27 |
Correct |
112 ms |
165248 KB |
Output is correct |
28 |
Correct |
110 ms |
165196 KB |
Output is correct |
29 |
Correct |
128 ms |
165192 KB |
Output is correct |
30 |
Correct |
107 ms |
165116 KB |
Output is correct |
31 |
Correct |
107 ms |
165096 KB |
Output is correct |
32 |
Correct |
119 ms |
165124 KB |
Output is correct |
33 |
Correct |
129 ms |
165264 KB |
Output is correct |
34 |
Correct |
118 ms |
165196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
148240 KB |
Output is correct |
2 |
Correct |
68 ms |
148172 KB |
Output is correct |
3 |
Correct |
68 ms |
148296 KB |
Output is correct |
4 |
Correct |
67 ms |
148264 KB |
Output is correct |
5 |
Correct |
66 ms |
148228 KB |
Output is correct |
6 |
Correct |
66 ms |
148304 KB |
Output is correct |
7 |
Correct |
66 ms |
148312 KB |
Output is correct |
8 |
Correct |
67 ms |
148428 KB |
Output is correct |
9 |
Correct |
68 ms |
148420 KB |
Output is correct |
10 |
Correct |
68 ms |
148684 KB |
Output is correct |
11 |
Correct |
70 ms |
148812 KB |
Output is correct |
12 |
Correct |
68 ms |
148800 KB |
Output is correct |
13 |
Correct |
80 ms |
148900 KB |
Output is correct |
14 |
Correct |
70 ms |
148816 KB |
Output is correct |
15 |
Correct |
69 ms |
148872 KB |
Output is correct |
16 |
Correct |
70 ms |
149572 KB |
Output is correct |
17 |
Correct |
86 ms |
154232 KB |
Output is correct |
18 |
Correct |
102 ms |
162976 KB |
Output is correct |
19 |
Correct |
107 ms |
165192 KB |
Output is correct |
20 |
Correct |
105 ms |
165232 KB |
Output is correct |
21 |
Correct |
79 ms |
150984 KB |
Output is correct |
22 |
Correct |
100 ms |
163264 KB |
Output is correct |
23 |
Correct |
95 ms |
161596 KB |
Output is correct |
24 |
Correct |
108 ms |
164412 KB |
Output is correct |
25 |
Correct |
120 ms |
165176 KB |
Output is correct |
26 |
Correct |
104 ms |
165308 KB |
Output is correct |
27 |
Correct |
108 ms |
165260 KB |
Output is correct |
28 |
Correct |
112 ms |
165240 KB |
Output is correct |
29 |
Correct |
128 ms |
165228 KB |
Output is correct |
30 |
Correct |
105 ms |
165316 KB |
Output is correct |
31 |
Correct |
112 ms |
165144 KB |
Output is correct |
32 |
Correct |
107 ms |
165204 KB |
Output is correct |
33 |
Correct |
125 ms |
165236 KB |
Output is correct |
34 |
Correct |
118 ms |
165148 KB |
Output is correct |
35 |
Correct |
141 ms |
160996 KB |
Output is correct |
36 |
Correct |
97 ms |
157424 KB |
Output is correct |
37 |
Correct |
147 ms |
166212 KB |
Output is correct |
38 |
Correct |
147 ms |
166668 KB |
Output is correct |
39 |
Correct |
174 ms |
166684 KB |
Output is correct |
40 |
Correct |
152 ms |
166760 KB |
Output is correct |
41 |
Correct |
144 ms |
166600 KB |
Output is correct |
42 |
Correct |
123 ms |
165484 KB |
Output is correct |
43 |
Correct |
122 ms |
166040 KB |
Output is correct |
44 |
Correct |
107 ms |
165664 KB |
Output is correct |
45 |
Correct |
208 ms |
171844 KB |
Output is correct |
46 |
Correct |
233 ms |
171740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
148400 KB |
Output is correct |
2 |
Correct |
67 ms |
148180 KB |
Output is correct |
3 |
Correct |
69 ms |
148176 KB |
Output is correct |
4 |
Correct |
73 ms |
148276 KB |
Output is correct |
5 |
Correct |
84 ms |
148204 KB |
Output is correct |
6 |
Correct |
69 ms |
148304 KB |
Output is correct |
7 |
Correct |
68 ms |
148212 KB |
Output is correct |
8 |
Correct |
68 ms |
148352 KB |
Output is correct |
9 |
Correct |
67 ms |
148532 KB |
Output is correct |
10 |
Correct |
68 ms |
148752 KB |
Output is correct |
11 |
Correct |
70 ms |
148812 KB |
Output is correct |
12 |
Correct |
69 ms |
148972 KB |
Output is correct |
13 |
Correct |
68 ms |
148720 KB |
Output is correct |
14 |
Correct |
70 ms |
148812 KB |
Output is correct |
15 |
Correct |
69 ms |
148848 KB |
Output is correct |
16 |
Correct |
70 ms |
149384 KB |
Output is correct |
17 |
Correct |
89 ms |
154224 KB |
Output is correct |
18 |
Correct |
102 ms |
163004 KB |
Output is correct |
19 |
Correct |
104 ms |
165096 KB |
Output is correct |
20 |
Correct |
127 ms |
165152 KB |
Output is correct |
21 |
Correct |
73 ms |
151104 KB |
Output is correct |
22 |
Correct |
100 ms |
163204 KB |
Output is correct |
23 |
Correct |
98 ms |
161788 KB |
Output is correct |
24 |
Correct |
105 ms |
164296 KB |
Output is correct |
25 |
Correct |
104 ms |
165120 KB |
Output is correct |
26 |
Correct |
114 ms |
165148 KB |
Output is correct |
27 |
Correct |
111 ms |
165152 KB |
Output is correct |
28 |
Correct |
113 ms |
165264 KB |
Output is correct |
29 |
Correct |
133 ms |
165204 KB |
Output is correct |
30 |
Correct |
105 ms |
165152 KB |
Output is correct |
31 |
Correct |
151 ms |
165220 KB |
Output is correct |
32 |
Correct |
121 ms |
165208 KB |
Output is correct |
33 |
Correct |
126 ms |
165232 KB |
Output is correct |
34 |
Correct |
119 ms |
165188 KB |
Output is correct |
35 |
Correct |
122 ms |
161020 KB |
Output is correct |
36 |
Correct |
97 ms |
157244 KB |
Output is correct |
37 |
Correct |
170 ms |
166348 KB |
Output is correct |
38 |
Correct |
149 ms |
166624 KB |
Output is correct |
39 |
Correct |
147 ms |
166668 KB |
Output is correct |
40 |
Correct |
157 ms |
166664 KB |
Output is correct |
41 |
Correct |
196 ms |
166588 KB |
Output is correct |
42 |
Correct |
111 ms |
165460 KB |
Output is correct |
43 |
Correct |
112 ms |
166220 KB |
Output is correct |
44 |
Correct |
110 ms |
165584 KB |
Output is correct |
45 |
Correct |
214 ms |
171748 KB |
Output is correct |
46 |
Correct |
211 ms |
171732 KB |
Output is correct |
47 |
Runtime error |
262 ms |
262144 KB |
Execution killed with signal 9 |
48 |
Halted |
0 ms |
0 KB |
- |