#include <bits/stdc++.h>
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<short,short>
#define SF(x) scanf("%Id",&x)
#define SF2(x,y) scanf("%Id%Id",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
using namespace std;
const long long INF = 1e9+1;
const long long MOD = 1e9+7;
const int MX=200015;
int sq=200;
int n,m;
bool vis[30005][280];
vector<short int> v[30005];
int f,t;
priority_queue< pair<int,pii> , vector< pair<int,pii> > , greater< pair<int,pii> > > pq;
void dijkstra(){
pq.P({0,{f,0}});
int j,ver,val;
W(!pq.empty()){
val=pq.top().F;
ver=pq.top().S.F;
j=pq.top().S.S;
pq.pop();
if(vis[ver][j])continue;
vis[ver][j]=1;
// cout<<ver<<" "<<j<<" "<<val<<endl;
if(ver==t){
cout<<val;
exit(0);
}
if(j==0){
for(auto i : v[ver]){
if(i<sq){
if(vis[ver][i]==0)
pq.P({val,{ver,i}});
}
else{
short o=1;
for(int j=ver-i;j>=0;j-=i){
if(vis[j][0]==0)
pq.P({o+val,{j,0}});
o++;
}
o=1;
for(int j=ver+i;j<n;j+=i){
if(vis[j][0]==0)
pq.P({o+val,{j,0}});
o++;
}
}
}
}
else{
if(ver-j>=0){
if(vis[ver-j][j]==0)
pq.P({val+1,{ver-j,j}});
if(vis[ver-j][0]==0)
pq.P({val+1,{ver-j,0}});
}
if(ver+j<n){
if(vis[ver+j][j]==0)
pq.P({val+1,{ver+j,j}});
if(vis[ver+j][0]==0)
pq.P({val+1,{ver+j,0}});
}
}
}
}
int main(){
// short s=60000;
// cout<<s;
cin>>n>>m;
for(int i=0;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
if(i==0)f=x;
if(i==1)t=x;
v[x].pb(y);
}
dijkstra();
cout<<-1;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:94:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1120 KB |
Output is correct |
3 |
Correct |
2 ms |
1192 KB |
Output is correct |
4 |
Correct |
2 ms |
1264 KB |
Output is correct |
5 |
Correct |
2 ms |
1264 KB |
Output is correct |
6 |
Correct |
2 ms |
1264 KB |
Output is correct |
7 |
Correct |
2 ms |
1264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1264 KB |
Output is correct |
2 |
Correct |
2 ms |
1264 KB |
Output is correct |
3 |
Correct |
2 ms |
1264 KB |
Output is correct |
4 |
Correct |
2 ms |
1264 KB |
Output is correct |
5 |
Correct |
2 ms |
1264 KB |
Output is correct |
6 |
Correct |
2 ms |
1264 KB |
Output is correct |
7 |
Correct |
2 ms |
1264 KB |
Output is correct |
8 |
Correct |
2 ms |
1264 KB |
Output is correct |
9 |
Correct |
2 ms |
1264 KB |
Output is correct |
10 |
Correct |
2 ms |
1264 KB |
Output is correct |
11 |
Correct |
3 ms |
1264 KB |
Output is correct |
12 |
Correct |
2 ms |
1388 KB |
Output is correct |
13 |
Correct |
3 ms |
1388 KB |
Output is correct |
14 |
Correct |
3 ms |
1388 KB |
Output is correct |
15 |
Correct |
3 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1388 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
3 ms |
1388 KB |
Output is correct |
4 |
Correct |
2 ms |
1388 KB |
Output is correct |
5 |
Correct |
2 ms |
1388 KB |
Output is correct |
6 |
Correct |
2 ms |
1388 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
2 ms |
1388 KB |
Output is correct |
9 |
Correct |
2 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
1388 KB |
Output is correct |
11 |
Correct |
2 ms |
1388 KB |
Output is correct |
12 |
Correct |
2 ms |
1388 KB |
Output is correct |
13 |
Correct |
3 ms |
1388 KB |
Output is correct |
14 |
Correct |
4 ms |
1516 KB |
Output is correct |
15 |
Correct |
4 ms |
1516 KB |
Output is correct |
16 |
Correct |
2 ms |
1516 KB |
Output is correct |
17 |
Correct |
3 ms |
1516 KB |
Output is correct |
18 |
Correct |
2 ms |
1516 KB |
Output is correct |
19 |
Correct |
3 ms |
1516 KB |
Output is correct |
20 |
Correct |
4 ms |
1900 KB |
Output is correct |
21 |
Correct |
2 ms |
1900 KB |
Output is correct |
22 |
Correct |
3 ms |
1900 KB |
Output is correct |
23 |
Correct |
3 ms |
1900 KB |
Output is correct |
24 |
Correct |
4 ms |
1900 KB |
Output is correct |
25 |
Correct |
3 ms |
1900 KB |
Output is correct |
26 |
Correct |
3 ms |
1900 KB |
Output is correct |
27 |
Correct |
3 ms |
1900 KB |
Output is correct |
28 |
Correct |
4 ms |
1900 KB |
Output is correct |
29 |
Correct |
11 ms |
1900 KB |
Output is correct |
30 |
Correct |
4 ms |
1900 KB |
Output is correct |
31 |
Correct |
7 ms |
1900 KB |
Output is correct |
32 |
Correct |
5 ms |
1900 KB |
Output is correct |
33 |
Correct |
19 ms |
1900 KB |
Output is correct |
34 |
Correct |
15 ms |
1988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1988 KB |
Output is correct |
2 |
Correct |
2 ms |
1988 KB |
Output is correct |
3 |
Correct |
3 ms |
1988 KB |
Output is correct |
4 |
Correct |
2 ms |
1988 KB |
Output is correct |
5 |
Correct |
2 ms |
1988 KB |
Output is correct |
6 |
Correct |
2 ms |
1988 KB |
Output is correct |
7 |
Correct |
2 ms |
1988 KB |
Output is correct |
8 |
Correct |
3 ms |
1988 KB |
Output is correct |
9 |
Correct |
3 ms |
1988 KB |
Output is correct |
10 |
Correct |
2 ms |
1988 KB |
Output is correct |
11 |
Correct |
2 ms |
1988 KB |
Output is correct |
12 |
Correct |
2 ms |
1988 KB |
Output is correct |
13 |
Correct |
2 ms |
1988 KB |
Output is correct |
14 |
Correct |
4 ms |
1988 KB |
Output is correct |
15 |
Correct |
4 ms |
1988 KB |
Output is correct |
16 |
Correct |
2 ms |
1988 KB |
Output is correct |
17 |
Correct |
4 ms |
1988 KB |
Output is correct |
18 |
Correct |
3 ms |
1988 KB |
Output is correct |
19 |
Correct |
2 ms |
1988 KB |
Output is correct |
20 |
Correct |
4 ms |
1988 KB |
Output is correct |
21 |
Correct |
2 ms |
1988 KB |
Output is correct |
22 |
Correct |
2 ms |
1988 KB |
Output is correct |
23 |
Correct |
4 ms |
1988 KB |
Output is correct |
24 |
Correct |
4 ms |
1988 KB |
Output is correct |
25 |
Correct |
3 ms |
1988 KB |
Output is correct |
26 |
Correct |
3 ms |
1988 KB |
Output is correct |
27 |
Correct |
3 ms |
1988 KB |
Output is correct |
28 |
Correct |
3 ms |
1988 KB |
Output is correct |
29 |
Correct |
12 ms |
1988 KB |
Output is correct |
30 |
Correct |
4 ms |
1988 KB |
Output is correct |
31 |
Correct |
6 ms |
1988 KB |
Output is correct |
32 |
Correct |
7 ms |
1988 KB |
Output is correct |
33 |
Correct |
22 ms |
1988 KB |
Output is correct |
34 |
Correct |
17 ms |
1988 KB |
Output is correct |
35 |
Correct |
16 ms |
2032 KB |
Output is correct |
36 |
Correct |
4 ms |
2032 KB |
Output is correct |
37 |
Correct |
10 ms |
2284 KB |
Output is correct |
38 |
Correct |
14 ms |
2284 KB |
Output is correct |
39 |
Correct |
10 ms |
2284 KB |
Output is correct |
40 |
Correct |
11 ms |
2284 KB |
Output is correct |
41 |
Correct |
10 ms |
2284 KB |
Output is correct |
42 |
Correct |
9 ms |
2284 KB |
Output is correct |
43 |
Correct |
8 ms |
2284 KB |
Output is correct |
44 |
Correct |
12 ms |
2288 KB |
Output is correct |
45 |
Correct |
112 ms |
3036 KB |
Output is correct |
46 |
Correct |
81 ms |
3048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3048 KB |
Output is correct |
2 |
Correct |
2 ms |
3048 KB |
Output is correct |
3 |
Correct |
2 ms |
3048 KB |
Output is correct |
4 |
Correct |
2 ms |
3048 KB |
Output is correct |
5 |
Correct |
2 ms |
3048 KB |
Output is correct |
6 |
Correct |
2 ms |
3048 KB |
Output is correct |
7 |
Correct |
2 ms |
3048 KB |
Output is correct |
8 |
Correct |
2 ms |
3048 KB |
Output is correct |
9 |
Correct |
2 ms |
3048 KB |
Output is correct |
10 |
Correct |
2 ms |
3048 KB |
Output is correct |
11 |
Correct |
2 ms |
3048 KB |
Output is correct |
12 |
Correct |
2 ms |
3048 KB |
Output is correct |
13 |
Correct |
2 ms |
3048 KB |
Output is correct |
14 |
Correct |
3 ms |
3048 KB |
Output is correct |
15 |
Correct |
3 ms |
3048 KB |
Output is correct |
16 |
Correct |
2 ms |
3048 KB |
Output is correct |
17 |
Correct |
3 ms |
3048 KB |
Output is correct |
18 |
Correct |
2 ms |
3048 KB |
Output is correct |
19 |
Correct |
2 ms |
3048 KB |
Output is correct |
20 |
Correct |
3 ms |
3048 KB |
Output is correct |
21 |
Correct |
3 ms |
3048 KB |
Output is correct |
22 |
Correct |
3 ms |
3048 KB |
Output is correct |
23 |
Correct |
3 ms |
3048 KB |
Output is correct |
24 |
Correct |
4 ms |
3048 KB |
Output is correct |
25 |
Correct |
3 ms |
3048 KB |
Output is correct |
26 |
Correct |
3 ms |
3048 KB |
Output is correct |
27 |
Correct |
3 ms |
3048 KB |
Output is correct |
28 |
Correct |
4 ms |
3048 KB |
Output is correct |
29 |
Correct |
13 ms |
3048 KB |
Output is correct |
30 |
Correct |
4 ms |
3048 KB |
Output is correct |
31 |
Correct |
7 ms |
3048 KB |
Output is correct |
32 |
Correct |
6 ms |
3048 KB |
Output is correct |
33 |
Correct |
23 ms |
3048 KB |
Output is correct |
34 |
Correct |
19 ms |
3048 KB |
Output is correct |
35 |
Correct |
12 ms |
3048 KB |
Output is correct |
36 |
Correct |
4 ms |
3048 KB |
Output is correct |
37 |
Correct |
10 ms |
3048 KB |
Output is correct |
38 |
Correct |
11 ms |
3048 KB |
Output is correct |
39 |
Correct |
10 ms |
3048 KB |
Output is correct |
40 |
Correct |
12 ms |
3048 KB |
Output is correct |
41 |
Correct |
11 ms |
3048 KB |
Output is correct |
42 |
Correct |
7 ms |
3048 KB |
Output is correct |
43 |
Correct |
8 ms |
3048 KB |
Output is correct |
44 |
Correct |
11 ms |
3048 KB |
Output is correct |
45 |
Correct |
105 ms |
3048 KB |
Output is correct |
46 |
Correct |
78 ms |
3048 KB |
Output is correct |
47 |
Correct |
23 ms |
6120 KB |
Output is correct |
48 |
Correct |
12 ms |
6120 KB |
Output is correct |
49 |
Correct |
11 ms |
6120 KB |
Output is correct |
50 |
Correct |
8 ms |
6120 KB |
Output is correct |
51 |
Correct |
30 ms |
10476 KB |
Output is correct |
52 |
Correct |
31 ms |
10604 KB |
Output is correct |
53 |
Correct |
18 ms |
10604 KB |
Output is correct |
54 |
Correct |
11 ms |
10604 KB |
Output is correct |
55 |
Correct |
12 ms |
10604 KB |
Output is correct |
56 |
Correct |
22 ms |
10604 KB |
Output is correct |
57 |
Correct |
3 ms |
10604 KB |
Output is correct |
58 |
Correct |
25 ms |
10604 KB |
Output is correct |
59 |
Correct |
20 ms |
10604 KB |
Output is correct |
60 |
Correct |
18 ms |
10604 KB |
Output is correct |
61 |
Correct |
18 ms |
10604 KB |
Output is correct |
62 |
Correct |
41 ms |
10604 KB |
Output is correct |
63 |
Correct |
367 ms |
16748 KB |
Output is correct |
64 |
Correct |
367 ms |
17216 KB |
Output is correct |
65 |
Execution timed out |
1066 ms |
21680 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |