#include <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<pair<int,int>> q;
vector<int> buildings[30001];
int power[30001];
int distn[30001];
bool visited[30001];
const int INF = 1e15;
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(distn[i]>((abs(building-i)/power[x])-dist)){
q.emplace(dist-(abs(building-i)/power[x]),i);
distn[i] = (abs(building-i)/power[x])-dist;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for(int&i:distn)i=INF;
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;
distn[curr.second] = -curr.first;
for(int&i:buildings[curr.second])adddoge(i,curr.second,curr.first);
}
cout << (distn[tar]>=INF ? -1 : distn[tar]) << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
1372 KB |
Output is correct |
11 |
Correct |
2 ms |
1368 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Correct |
2 ms |
1372 KB |
Output is correct |
14 |
Correct |
1 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1368 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1404 KB |
Output is correct |
6 |
Correct |
1 ms |
1368 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
1260 KB |
Output is correct |
10 |
Correct |
1 ms |
1372 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Correct |
2 ms |
1368 KB |
Output is correct |
14 |
Correct |
1 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1372 KB |
Output is correct |
16 |
Correct |
1 ms |
1372 KB |
Output is correct |
17 |
Correct |
1 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1372 KB |
Output is correct |
19 |
Correct |
1 ms |
1368 KB |
Output is correct |
20 |
Correct |
23 ms |
1620 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1372 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1368 KB |
Output is correct |
26 |
Correct |
21 ms |
1372 KB |
Output is correct |
27 |
Correct |
20 ms |
1372 KB |
Output is correct |
28 |
Correct |
1 ms |
1372 KB |
Output is correct |
29 |
Correct |
2 ms |
1628 KB |
Output is correct |
30 |
Correct |
1 ms |
1372 KB |
Output is correct |
31 |
Correct |
2 ms |
1628 KB |
Output is correct |
32 |
Correct |
1 ms |
1408 KB |
Output is correct |
33 |
Correct |
3 ms |
1628 KB |
Output is correct |
34 |
Correct |
3 ms |
1824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1412 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
1368 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Correct |
2 ms |
1368 KB |
Output is correct |
14 |
Correct |
1 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1424 KB |
Output is correct |
16 |
Correct |
1 ms |
1372 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
2 ms |
1372 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1420 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1372 KB |
Output is correct |
26 |
Correct |
22 ms |
1500 KB |
Output is correct |
27 |
Correct |
20 ms |
1368 KB |
Output is correct |
28 |
Correct |
1 ms |
1368 KB |
Output is correct |
29 |
Correct |
2 ms |
1628 KB |
Output is correct |
30 |
Correct |
1 ms |
1372 KB |
Output is correct |
31 |
Correct |
2 ms |
1628 KB |
Output is correct |
32 |
Correct |
2 ms |
1628 KB |
Output is correct |
33 |
Correct |
2 ms |
1624 KB |
Output is correct |
34 |
Correct |
3 ms |
1884 KB |
Output is correct |
35 |
Correct |
6 ms |
2248 KB |
Output is correct |
36 |
Correct |
2 ms |
1424 KB |
Output is correct |
37 |
Correct |
6 ms |
2192 KB |
Output is correct |
38 |
Correct |
7 ms |
2396 KB |
Output is correct |
39 |
Correct |
7 ms |
2396 KB |
Output is correct |
40 |
Correct |
7 ms |
2488 KB |
Output is correct |
41 |
Correct |
7 ms |
2396 KB |
Output is correct |
42 |
Correct |
336 ms |
2140 KB |
Output is correct |
43 |
Correct |
330 ms |
2136 KB |
Output is correct |
44 |
Correct |
340 ms |
2140 KB |
Output is correct |
45 |
Correct |
7 ms |
2392 KB |
Output is correct |
46 |
Correct |
7 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
1 ms |
1372 KB |
Output is correct |
7 |
Correct |
1 ms |
1372 KB |
Output is correct |
8 |
Correct |
1 ms |
1368 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
1412 KB |
Output is correct |
11 |
Correct |
1 ms |
1372 KB |
Output is correct |
12 |
Correct |
2 ms |
1372 KB |
Output is correct |
13 |
Correct |
2 ms |
1372 KB |
Output is correct |
14 |
Correct |
1 ms |
1368 KB |
Output is correct |
15 |
Correct |
1 ms |
1372 KB |
Output is correct |
16 |
Correct |
1 ms |
1372 KB |
Output is correct |
17 |
Correct |
1 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
1372 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
23 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
1 ms |
1372 KB |
Output is correct |
24 |
Correct |
2 ms |
1372 KB |
Output is correct |
25 |
Correct |
2 ms |
1372 KB |
Output is correct |
26 |
Correct |
21 ms |
1372 KB |
Output is correct |
27 |
Correct |
20 ms |
1368 KB |
Output is correct |
28 |
Correct |
1 ms |
1372 KB |
Output is correct |
29 |
Correct |
2 ms |
1628 KB |
Output is correct |
30 |
Correct |
1 ms |
1372 KB |
Output is correct |
31 |
Correct |
1 ms |
1628 KB |
Output is correct |
32 |
Correct |
1 ms |
1560 KB |
Output is correct |
33 |
Correct |
2 ms |
1628 KB |
Output is correct |
34 |
Correct |
3 ms |
1628 KB |
Output is correct |
35 |
Correct |
5 ms |
2220 KB |
Output is correct |
36 |
Correct |
2 ms |
1624 KB |
Output is correct |
37 |
Correct |
6 ms |
2140 KB |
Output is correct |
38 |
Correct |
7 ms |
2396 KB |
Output is correct |
39 |
Correct |
7 ms |
2396 KB |
Output is correct |
40 |
Correct |
7 ms |
2392 KB |
Output is correct |
41 |
Correct |
7 ms |
2396 KB |
Output is correct |
42 |
Correct |
335 ms |
2124 KB |
Output is correct |
43 |
Correct |
331 ms |
2140 KB |
Output is correct |
44 |
Correct |
339 ms |
2136 KB |
Output is correct |
45 |
Correct |
7 ms |
2396 KB |
Output is correct |
46 |
Correct |
7 ms |
2440 KB |
Output is correct |
47 |
Correct |
17 ms |
3288 KB |
Output is correct |
48 |
Correct |
5 ms |
2140 KB |
Output is correct |
49 |
Correct |
4 ms |
2136 KB |
Output is correct |
50 |
Correct |
3 ms |
1884 KB |
Output is correct |
51 |
Correct |
22 ms |
4696 KB |
Output is correct |
52 |
Correct |
21 ms |
3544 KB |
Output is correct |
53 |
Correct |
12 ms |
3796 KB |
Output is correct |
54 |
Correct |
2 ms |
1756 KB |
Output is correct |
55 |
Correct |
3 ms |
1760 KB |
Output is correct |
56 |
Execution timed out |
1088 ms |
3392 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |