#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
using namespace std;
int n,m,B[30005],P[30005],v[30005];
queue<pair<pair<int,int>,int>> q;
vector<int> vt[30005];
bitset<30005> bit[30005];
void f(int now,int p,int cost){
if(!v[now]){
v[now]=1;
for(int i:vt[now]){
if(!bit[now][i]){
bit[now][i]=1;
q.push({{now,i},cost});
}
}
}
if(!bit[now][p]){
bit[now][p]=1;
q.push({{now,p},cost});
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&B[i],&P[i]);
vt[B[i]].push_back(P[i]);
}
v[B[1]]=1;
for(int i:vt[B[1]]){
if(!bit[B[1]][i]){
bit[B[1]][i]=1;
q.push({{B[1],i},0});
}
}
while(!q.empty()){
int now=q.front().x.x,p=q.front().x.y,cost=q.front().y; q.pop();
if(now==B[2]) return !printf("%d",cost);
if(now-p>=0) f(now-p,p,cost+1);
if(now+p<n) f(now+p,p,cost+1);
}
printf("-1");
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
27 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
29 | scanf("%d%d",&B[i],&P[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
2 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
1004 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 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 |
2 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
2 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
2 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1152 KB |
Output is correct |
8 |
Correct |
1 ms |
1004 KB |
Output is correct |
9 |
Correct |
1 ms |
1132 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 |
2 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
2 ms |
1516 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
4 ms |
3820 KB |
Output is correct |
18 |
Correct |
2 ms |
1132 KB |
Output is correct |
19 |
Correct |
2 ms |
1132 KB |
Output is correct |
20 |
Correct |
7 ms |
8428 KB |
Output is correct |
21 |
Correct |
2 ms |
1132 KB |
Output is correct |
22 |
Correct |
2 ms |
1132 KB |
Output is correct |
23 |
Correct |
6 ms |
6400 KB |
Output is correct |
24 |
Correct |
7 ms |
7532 KB |
Output is correct |
25 |
Correct |
4 ms |
2540 KB |
Output is correct |
26 |
Correct |
6 ms |
7404 KB |
Output is correct |
27 |
Correct |
7 ms |
7788 KB |
Output is correct |
28 |
Correct |
8 ms |
8428 KB |
Output is correct |
29 |
Correct |
9 ms |
8428 KB |
Output is correct |
30 |
Correct |
9 ms |
8428 KB |
Output is correct |
31 |
Correct |
8 ms |
8428 KB |
Output is correct |
32 |
Correct |
7 ms |
8428 KB |
Output is correct |
33 |
Correct |
12 ms |
8428 KB |
Output is correct |
34 |
Correct |
10 ms |
8428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
1004 KB |
Output is correct |
5 |
Correct |
2 ms |
1004 KB |
Output is correct |
6 |
Correct |
2 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
1004 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 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 |
2 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
2 ms |
1536 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
4 ms |
3820 KB |
Output is correct |
18 |
Correct |
2 ms |
1132 KB |
Output is correct |
19 |
Correct |
2 ms |
1132 KB |
Output is correct |
20 |
Correct |
7 ms |
8428 KB |
Output is correct |
21 |
Correct |
2 ms |
1132 KB |
Output is correct |
22 |
Correct |
2 ms |
1132 KB |
Output is correct |
23 |
Correct |
6 ms |
6380 KB |
Output is correct |
24 |
Correct |
7 ms |
7532 KB |
Output is correct |
25 |
Correct |
3 ms |
2540 KB |
Output is correct |
26 |
Correct |
6 ms |
7404 KB |
Output is correct |
27 |
Correct |
7 ms |
7788 KB |
Output is correct |
28 |
Correct |
8 ms |
8428 KB |
Output is correct |
29 |
Correct |
9 ms |
8428 KB |
Output is correct |
30 |
Correct |
7 ms |
8428 KB |
Output is correct |
31 |
Correct |
8 ms |
8428 KB |
Output is correct |
32 |
Correct |
8 ms |
8428 KB |
Output is correct |
33 |
Correct |
12 ms |
8428 KB |
Output is correct |
34 |
Correct |
10 ms |
8428 KB |
Output is correct |
35 |
Correct |
16 ms |
7276 KB |
Output is correct |
36 |
Correct |
5 ms |
2924 KB |
Output is correct |
37 |
Correct |
13 ms |
8940 KB |
Output is correct |
38 |
Correct |
16 ms |
9452 KB |
Output is correct |
39 |
Correct |
9 ms |
2284 KB |
Output is correct |
40 |
Correct |
11 ms |
4588 KB |
Output is correct |
41 |
Correct |
15 ms |
8940 KB |
Output is correct |
42 |
Correct |
11 ms |
7916 KB |
Output is correct |
43 |
Correct |
11 ms |
8428 KB |
Output is correct |
44 |
Correct |
12 ms |
9068 KB |
Output is correct |
45 |
Correct |
31 ms |
9452 KB |
Output is correct |
46 |
Correct |
21 ms |
9452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1004 KB |
Output is correct |
2 |
Correct |
1 ms |
1004 KB |
Output is correct |
3 |
Correct |
1 ms |
1004 KB |
Output is correct |
4 |
Correct |
1 ms |
1004 KB |
Output is correct |
5 |
Correct |
1 ms |
1004 KB |
Output is correct |
6 |
Correct |
1 ms |
1004 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
2 ms |
1004 KB |
Output is correct |
9 |
Correct |
2 ms |
1132 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 |
2 ms |
1388 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
3 ms |
1516 KB |
Output is correct |
16 |
Correct |
2 ms |
1004 KB |
Output is correct |
17 |
Correct |
5 ms |
3820 KB |
Output is correct |
18 |
Correct |
2 ms |
1132 KB |
Output is correct |
19 |
Correct |
2 ms |
1132 KB |
Output is correct |
20 |
Correct |
7 ms |
8428 KB |
Output is correct |
21 |
Correct |
2 ms |
1132 KB |
Output is correct |
22 |
Correct |
3 ms |
1132 KB |
Output is correct |
23 |
Correct |
8 ms |
6380 KB |
Output is correct |
24 |
Correct |
7 ms |
7532 KB |
Output is correct |
25 |
Correct |
3 ms |
2540 KB |
Output is correct |
26 |
Correct |
6 ms |
7404 KB |
Output is correct |
27 |
Correct |
7 ms |
7788 KB |
Output is correct |
28 |
Correct |
8 ms |
8428 KB |
Output is correct |
29 |
Correct |
9 ms |
8428 KB |
Output is correct |
30 |
Correct |
7 ms |
8428 KB |
Output is correct |
31 |
Correct |
8 ms |
8428 KB |
Output is correct |
32 |
Correct |
8 ms |
8448 KB |
Output is correct |
33 |
Correct |
11 ms |
8428 KB |
Output is correct |
34 |
Correct |
9 ms |
8428 KB |
Output is correct |
35 |
Correct |
17 ms |
7276 KB |
Output is correct |
36 |
Correct |
4 ms |
2924 KB |
Output is correct |
37 |
Correct |
13 ms |
8940 KB |
Output is correct |
38 |
Correct |
17 ms |
9528 KB |
Output is correct |
39 |
Correct |
11 ms |
2248 KB |
Output is correct |
40 |
Correct |
13 ms |
4588 KB |
Output is correct |
41 |
Correct |
17 ms |
8940 KB |
Output is correct |
42 |
Correct |
11 ms |
7916 KB |
Output is correct |
43 |
Correct |
12 ms |
8428 KB |
Output is correct |
44 |
Correct |
13 ms |
9068 KB |
Output is correct |
45 |
Correct |
33 ms |
9452 KB |
Output is correct |
46 |
Correct |
21 ms |
9452 KB |
Output is correct |
47 |
Correct |
32 ms |
31084 KB |
Output is correct |
48 |
Correct |
10 ms |
1900 KB |
Output is correct |
49 |
Correct |
8 ms |
1900 KB |
Output is correct |
50 |
Correct |
6 ms |
1644 KB |
Output is correct |
51 |
Correct |
85 ms |
86380 KB |
Output is correct |
52 |
Correct |
87 ms |
94828 KB |
Output is correct |
53 |
Correct |
25 ms |
18924 KB |
Output is correct |
54 |
Correct |
46 ms |
61420 KB |
Output is correct |
55 |
Correct |
59 ms |
78020 KB |
Output is correct |
56 |
Correct |
97 ms |
112628 KB |
Output is correct |
57 |
Correct |
3 ms |
2796 KB |
Output is correct |
58 |
Correct |
94 ms |
111980 KB |
Output is correct |
59 |
Correct |
94 ms |
104172 KB |
Output is correct |
60 |
Correct |
95 ms |
104172 KB |
Output is correct |
61 |
Correct |
84 ms |
99200 KB |
Output is correct |
62 |
Correct |
145 ms |
112748 KB |
Output is correct |
63 |
Correct |
289 ms |
112320 KB |
Output is correct |
64 |
Correct |
353 ms |
112108 KB |
Output is correct |
65 |
Correct |
438 ms |
112356 KB |
Output is correct |
66 |
Correct |
649 ms |
112236 KB |
Output is correct |
67 |
Correct |
393 ms |
112224 KB |
Output is correct |