#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
#define pii pair<int,int>
#define supercepat ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
using namespace std;
int tc,ans=0,n,m;
int b[30005],p[30005];
vector<int> vec[30005];
pqueue<pii> a;
int dis[30005];
void djikstra(int x){
a.push(pii(0,x));
while(!a.empty()){
int idx=a.top().sec; // nomor gedung
if(idx==b[1]) break;
int dist=-1*a.top().fi;
a.pop();
if(dis[idx]<dist){
continue;
}
else{
for(auto i : vec[idx]){
for(int j = idx+p[i];j<n;j+=p[i]){
if(dis[j]>dist+(abs(j-idx)/p[i])){
dis[j]=dist+(abs(j-idx)/p[i]);
a.push(pii(-1*dis[j],j));
}
}
for(int j = idx-p[i];j>=0;j-=p[i]){
if(dis[j]>dist+(abs(j-idx)/p[i])){
dis[j]=dist+(abs(j-idx)/p[i]);
a.push(pii(-1*dis[j],j));
}
}
}
}
}
}
main(){
supercepat;
cin>>n>>m;
for(int i=0;i<n;i++) dis[i]=INT_MAX;
for(int i=0;i<m;i++){
cin>>b[i]>>p[i];
vec[b[i]].pb(i);
}
dis[b[0]]=0;
djikstra(b[0]);
if(dis[b[1]]==INT_MAX) cout<<-1<<endl;
else cout<<dis[b[1]]<<endl;
}
Compilation message
skyscraper.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
936 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
1040 KB |
Output is correct |
20 |
Correct |
23 ms |
1232 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
2 ms |
1236 KB |
Output is correct |
30 |
Correct |
2 ms |
1236 KB |
Output is correct |
31 |
Correct |
2 ms |
1236 KB |
Output is correct |
32 |
Correct |
2 ms |
1236 KB |
Output is correct |
33 |
Correct |
2 ms |
1364 KB |
Output is correct |
34 |
Correct |
2 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1044 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1044 KB |
Output is correct |
19 |
Correct |
1 ms |
1040 KB |
Output is correct |
20 |
Correct |
24 ms |
1208 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
1040 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1172 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1052 KB |
Output is correct |
28 |
Correct |
2 ms |
1108 KB |
Output is correct |
29 |
Correct |
2 ms |
1292 KB |
Output is correct |
30 |
Correct |
1 ms |
1160 KB |
Output is correct |
31 |
Correct |
2 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1160 KB |
Output is correct |
33 |
Correct |
2 ms |
1364 KB |
Output is correct |
34 |
Correct |
2 ms |
1428 KB |
Output is correct |
35 |
Correct |
6 ms |
2068 KB |
Output is correct |
36 |
Correct |
2 ms |
1236 KB |
Output is correct |
37 |
Correct |
4 ms |
2004 KB |
Output is correct |
38 |
Correct |
9 ms |
2516 KB |
Output is correct |
39 |
Correct |
5 ms |
2232 KB |
Output is correct |
40 |
Correct |
7 ms |
2388 KB |
Output is correct |
41 |
Correct |
7 ms |
2388 KB |
Output is correct |
42 |
Correct |
4 ms |
2004 KB |
Output is correct |
43 |
Correct |
4 ms |
2068 KB |
Output is correct |
44 |
Correct |
338 ms |
2112 KB |
Output is correct |
45 |
Correct |
10 ms |
2260 KB |
Output is correct |
46 |
Correct |
7 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1044 KB |
Output is correct |
16 |
Correct |
1 ms |
1036 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
24 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
2 ms |
1172 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
1048 KB |
Output is correct |
27 |
Correct |
1 ms |
1048 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
3 ms |
1236 KB |
Output is correct |
30 |
Correct |
2 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1236 KB |
Output is correct |
33 |
Correct |
2 ms |
1364 KB |
Output is correct |
34 |
Correct |
2 ms |
1424 KB |
Output is correct |
35 |
Correct |
5 ms |
2072 KB |
Output is correct |
36 |
Correct |
2 ms |
1172 KB |
Output is correct |
37 |
Correct |
5 ms |
2004 KB |
Output is correct |
38 |
Correct |
9 ms |
2428 KB |
Output is correct |
39 |
Correct |
6 ms |
2200 KB |
Output is correct |
40 |
Correct |
6 ms |
2388 KB |
Output is correct |
41 |
Correct |
7 ms |
2388 KB |
Output is correct |
42 |
Correct |
4 ms |
2048 KB |
Output is correct |
43 |
Correct |
4 ms |
2004 KB |
Output is correct |
44 |
Correct |
339 ms |
2112 KB |
Output is correct |
45 |
Correct |
7 ms |
2260 KB |
Output is correct |
46 |
Correct |
7 ms |
2384 KB |
Output is correct |
47 |
Correct |
8 ms |
3316 KB |
Output is correct |
48 |
Correct |
5 ms |
2268 KB |
Output is correct |
49 |
Correct |
5 ms |
2252 KB |
Output is correct |
50 |
Correct |
5 ms |
2004 KB |
Output is correct |
51 |
Correct |
16 ms |
4868 KB |
Output is correct |
52 |
Correct |
14 ms |
3848 KB |
Output is correct |
53 |
Correct |
7 ms |
3076 KB |
Output is correct |
54 |
Correct |
2 ms |
1552 KB |
Output is correct |
55 |
Correct |
2 ms |
1624 KB |
Output is correct |
56 |
Execution timed out |
1087 ms |
3544 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |