#include <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<pair<int,int>> q;
vector<int> buildings[30001];
int power[30001];
bool visited[30001];
int n;
inline void adddoge(int x,int building,int dist){
int minimum = building-power[x]*(building/power[x]);
for(int i = minimum;i<n;i+=power[x])if(!visited[i]){
q.emplace(dist-(abs(building-i)/power[x]),i);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m;
cin >> n >> m;
int base,tar;
cin>>base>>power[0]>>tar>>power[1];
buildings[base].emplace_back(0);
buildings[tar].emplace_back(1);
for(int i=2;i<m;i++){
int b;cin>>b>>power[i];
buildings[b].emplace_back(i);
}
q.emplace(0,base);
while(!q.empty()){
auto curr = q.top();q.pop();
if(visited[curr.second])continue;
visited[curr.second]=true;
if(curr.second==tar){
cout << -curr.first << '\n';
return 0;
}
for(int&i:buildings[curr.second])adddoge(i,curr.second,curr.first);
}
cout << "-1\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1164 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1196 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1120 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1120 KB |
Output is correct |
8 |
Correct |
1 ms |
1124 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1120 KB |
Output is correct |
11 |
Correct |
1 ms |
1120 KB |
Output is correct |
12 |
Correct |
1 ms |
1120 KB |
Output is correct |
13 |
Correct |
1 ms |
1124 KB |
Output is correct |
14 |
Correct |
1 ms |
1216 KB |
Output is correct |
15 |
Correct |
1 ms |
1120 KB |
Output is correct |
16 |
Correct |
1 ms |
1128 KB |
Output is correct |
17 |
Correct |
1 ms |
1632 KB |
Output is correct |
18 |
Correct |
1 ms |
1120 KB |
Output is correct |
19 |
Correct |
1 ms |
1124 KB |
Output is correct |
20 |
Correct |
275 ms |
19656 KB |
Output is correct |
21 |
Correct |
1 ms |
1120 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
1 ms |
1124 KB |
Output is correct |
24 |
Correct |
2 ms |
1384 KB |
Output is correct |
25 |
Correct |
1 ms |
1252 KB |
Output is correct |
26 |
Correct |
1 ms |
1380 KB |
Output is correct |
27 |
Correct |
1 ms |
1120 KB |
Output is correct |
28 |
Correct |
1 ms |
1128 KB |
Output is correct |
29 |
Correct |
8 ms |
2328 KB |
Output is correct |
30 |
Correct |
3 ms |
1496 KB |
Output is correct |
31 |
Correct |
4 ms |
1764 KB |
Output is correct |
32 |
Correct |
2 ms |
1376 KB |
Output is correct |
33 |
Correct |
17 ms |
3296 KB |
Output is correct |
34 |
Correct |
11 ms |
3284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1124 KB |
Output is correct |
2 |
Correct |
1 ms |
1120 KB |
Output is correct |
3 |
Correct |
1 ms |
1124 KB |
Output is correct |
4 |
Correct |
1 ms |
1124 KB |
Output is correct |
5 |
Correct |
1 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
1112 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
268 ms |
19080 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
1 ms |
1112 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
8 ms |
2264 KB |
Output is correct |
30 |
Correct |
3 ms |
1500 KB |
Output is correct |
31 |
Correct |
4 ms |
1760 KB |
Output is correct |
32 |
Correct |
2 ms |
1372 KB |
Output is correct |
33 |
Correct |
17 ms |
3224 KB |
Output is correct |
34 |
Correct |
11 ms |
3284 KB |
Output is correct |
35 |
Correct |
7 ms |
3032 KB |
Output is correct |
36 |
Correct |
2 ms |
1372 KB |
Output is correct |
37 |
Correct |
6 ms |
3744 KB |
Output is correct |
38 |
Correct |
9 ms |
4048 KB |
Output is correct |
39 |
Correct |
5 ms |
2140 KB |
Output is correct |
40 |
Correct |
6 ms |
2520 KB |
Output is correct |
41 |
Correct |
8 ms |
4304 KB |
Output is correct |
42 |
Correct |
4 ms |
1884 KB |
Output is correct |
43 |
Correct |
4 ms |
1880 KB |
Output is correct |
44 |
Correct |
287 ms |
18544 KB |
Output is correct |
45 |
Correct |
67 ms |
10448 KB |
Output is correct |
46 |
Correct |
39 ms |
11468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1168 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1112 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1172 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1148 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1168 KB |
Output is correct |
20 |
Correct |
264 ms |
17856 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1116 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
2 ms |
1112 KB |
Output is correct |
29 |
Correct |
8 ms |
2264 KB |
Output is correct |
30 |
Correct |
2 ms |
1500 KB |
Output is correct |
31 |
Correct |
4 ms |
1760 KB |
Output is correct |
32 |
Correct |
2 ms |
1372 KB |
Output is correct |
33 |
Correct |
17 ms |
3288 KB |
Output is correct |
34 |
Correct |
10 ms |
3284 KB |
Output is correct |
35 |
Correct |
7 ms |
2992 KB |
Output is correct |
36 |
Correct |
2 ms |
1372 KB |
Output is correct |
37 |
Correct |
6 ms |
3768 KB |
Output is correct |
38 |
Correct |
9 ms |
4300 KB |
Output is correct |
39 |
Correct |
7 ms |
2140 KB |
Output is correct |
40 |
Correct |
6 ms |
2624 KB |
Output is correct |
41 |
Correct |
9 ms |
4192 KB |
Output is correct |
42 |
Correct |
4 ms |
1884 KB |
Output is correct |
43 |
Correct |
4 ms |
1908 KB |
Output is correct |
44 |
Correct |
285 ms |
19048 KB |
Output is correct |
45 |
Correct |
67 ms |
11212 KB |
Output is correct |
46 |
Correct |
44 ms |
11952 KB |
Output is correct |
47 |
Correct |
9 ms |
6352 KB |
Output is correct |
48 |
Correct |
5 ms |
1916 KB |
Output is correct |
49 |
Correct |
4 ms |
1884 KB |
Output is correct |
50 |
Correct |
3 ms |
1624 KB |
Output is correct |
51 |
Correct |
14 ms |
7116 KB |
Output is correct |
52 |
Correct |
16 ms |
8400 KB |
Output is correct |
53 |
Correct |
7 ms |
2652 KB |
Output is correct |
54 |
Correct |
2 ms |
1504 KB |
Output is correct |
55 |
Correct |
2 ms |
1504 KB |
Output is correct |
56 |
Runtime error |
200 ms |
262144 KB |
Execution killed with signal 9 |
57 |
Halted |
0 ms |
0 KB |
- |