#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
#include <bits/stdc++.h>
using namespace std;
const int MN = 30004, MS = 200;
int N, M, S, i, j, src, des, x, y, ent[MN];
struct pir{int f, s, p;}; vector<pir> e[MN]; bitset<MS> pw[MN];
pir pr(int f, int s, int p){pir z={f,s,p}; return z;}
struct pq{bool operator()(const pir&i,const pir&j){return(i.s>j.s);}};
priority_queue<pir,vector<pir>,pq> q;
int main(){
for(scanf("%d%d",&N,&M),S=sqrt(N+0.0);i<M;i++){
scanf("%d%d",&x,&y);
if(i == 0) src = x;
else if(i == 1) des = x;
if(y >= S){
for(j=1;x-j*y>=0;j++)
e[x].push_back(pr(x-j*y,j,-1));
for(j=1;x+j*y<N;j++)
e[x].push_back(pr(x+j*y,j,-1));
}
else e[x].push_back(pr(x,0,y));
}
pir st = {src, 0, -1}; q.push(st);
while(!q.empty()){
pir _ = q.top(); q.pop();
if(_.f == des){printf("%d\n",_.s); return 0;}
if(_.p == -1){
if(ent[_.f]) continue;
else ent[_.f] = 1;
for(auto v : e[_.f]){
if(v.p == -1 && !ent[v.f]) q.push(pr(v.f,v.s+_.s,v.p));
else if(v.p != -1 && !pw[v.f][v.p]) q.push(pr(v.f,v.s+_.s,v.p));
}
}
else{
if(pw[_.f][_.p]) continue;
else pw[_.f][_.p] = 1;
if(!ent[_.f]) q.push(pr(_.f,_.s,-1));
if(_.f+_.p < N && !pw[_.f+_.p][_.p]) q.push(pr(_.f+_.p,_.s+1,_.p));
if(_.f-_.p >=0 && !pw[_.f-_.p][_.p]) q.push(pr(_.f-_.p,_.s+1,_.p));
}
}
printf("-1\n");
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(scanf("%d%d",&N,&M),S=sqrt(N+0.0);i<M;i++){
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:16:8: 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 |
4 ms |
1128 KB |
Output is correct |
3 |
Correct |
3 ms |
1128 KB |
Output is correct |
4 |
Correct |
4 ms |
1128 KB |
Output is correct |
5 |
Correct |
3 ms |
1168 KB |
Output is correct |
6 |
Correct |
3 ms |
1168 KB |
Output is correct |
7 |
Correct |
3 ms |
1168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1212 KB |
Output is correct |
2 |
Correct |
3 ms |
1340 KB |
Output is correct |
3 |
Correct |
4 ms |
1340 KB |
Output is correct |
4 |
Correct |
3 ms |
1364 KB |
Output is correct |
5 |
Correct |
3 ms |
1364 KB |
Output is correct |
6 |
Correct |
3 ms |
1364 KB |
Output is correct |
7 |
Correct |
3 ms |
1388 KB |
Output is correct |
8 |
Correct |
3 ms |
1388 KB |
Output is correct |
9 |
Correct |
3 ms |
1388 KB |
Output is correct |
10 |
Correct |
3 ms |
1388 KB |
Output is correct |
11 |
Correct |
4 ms |
1404 KB |
Output is correct |
12 |
Correct |
4 ms |
1404 KB |
Output is correct |
13 |
Correct |
4 ms |
1404 KB |
Output is correct |
14 |
Correct |
3 ms |
1404 KB |
Output is correct |
15 |
Correct |
3 ms |
1404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1404 KB |
Output is correct |
2 |
Correct |
3 ms |
1404 KB |
Output is correct |
3 |
Correct |
3 ms |
1404 KB |
Output is correct |
4 |
Correct |
4 ms |
1404 KB |
Output is correct |
5 |
Correct |
3 ms |
1404 KB |
Output is correct |
6 |
Correct |
4 ms |
1404 KB |
Output is correct |
7 |
Correct |
4 ms |
1404 KB |
Output is correct |
8 |
Correct |
3 ms |
1404 KB |
Output is correct |
9 |
Correct |
3 ms |
1404 KB |
Output is correct |
10 |
Correct |
3 ms |
1404 KB |
Output is correct |
11 |
Correct |
4 ms |
1404 KB |
Output is correct |
12 |
Correct |
4 ms |
1404 KB |
Output is correct |
13 |
Correct |
4 ms |
1404 KB |
Output is correct |
14 |
Correct |
4 ms |
1404 KB |
Output is correct |
15 |
Correct |
4 ms |
1404 KB |
Output is correct |
16 |
Correct |
3 ms |
1404 KB |
Output is correct |
17 |
Correct |
5 ms |
1532 KB |
Output is correct |
18 |
Correct |
3 ms |
1532 KB |
Output is correct |
19 |
Correct |
3 ms |
1532 KB |
Output is correct |
20 |
Correct |
3 ms |
1532 KB |
Output is correct |
21 |
Correct |
3 ms |
1532 KB |
Output is correct |
22 |
Correct |
4 ms |
1532 KB |
Output is correct |
23 |
Correct |
4 ms |
1532 KB |
Output is correct |
24 |
Correct |
4 ms |
1532 KB |
Output is correct |
25 |
Correct |
4 ms |
1532 KB |
Output is correct |
26 |
Correct |
3 ms |
1532 KB |
Output is correct |
27 |
Correct |
3 ms |
1532 KB |
Output is correct |
28 |
Correct |
4 ms |
1532 KB |
Output is correct |
29 |
Correct |
9 ms |
1532 KB |
Output is correct |
30 |
Correct |
5 ms |
1532 KB |
Output is correct |
31 |
Correct |
6 ms |
1532 KB |
Output is correct |
32 |
Correct |
7 ms |
1788 KB |
Output is correct |
33 |
Correct |
20 ms |
2948 KB |
Output is correct |
34 |
Correct |
14 ms |
2948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2948 KB |
Output is correct |
2 |
Correct |
3 ms |
2948 KB |
Output is correct |
3 |
Correct |
3 ms |
2948 KB |
Output is correct |
4 |
Correct |
3 ms |
2948 KB |
Output is correct |
5 |
Correct |
4 ms |
2948 KB |
Output is correct |
6 |
Correct |
3 ms |
2948 KB |
Output is correct |
7 |
Correct |
4 ms |
2948 KB |
Output is correct |
8 |
Correct |
3 ms |
2948 KB |
Output is correct |
9 |
Correct |
3 ms |
2948 KB |
Output is correct |
10 |
Correct |
3 ms |
2948 KB |
Output is correct |
11 |
Correct |
4 ms |
2948 KB |
Output is correct |
12 |
Correct |
4 ms |
2948 KB |
Output is correct |
13 |
Correct |
3 ms |
2948 KB |
Output is correct |
14 |
Correct |
5 ms |
2948 KB |
Output is correct |
15 |
Correct |
4 ms |
2948 KB |
Output is correct |
16 |
Correct |
3 ms |
2948 KB |
Output is correct |
17 |
Correct |
6 ms |
2948 KB |
Output is correct |
18 |
Correct |
3 ms |
2948 KB |
Output is correct |
19 |
Correct |
3 ms |
2948 KB |
Output is correct |
20 |
Correct |
4 ms |
2948 KB |
Output is correct |
21 |
Correct |
3 ms |
2948 KB |
Output is correct |
22 |
Correct |
5 ms |
2948 KB |
Output is correct |
23 |
Correct |
5 ms |
2948 KB |
Output is correct |
24 |
Correct |
7 ms |
2948 KB |
Output is correct |
25 |
Correct |
4 ms |
2948 KB |
Output is correct |
26 |
Correct |
4 ms |
2948 KB |
Output is correct |
27 |
Correct |
4 ms |
2948 KB |
Output is correct |
28 |
Correct |
4 ms |
2948 KB |
Output is correct |
29 |
Correct |
10 ms |
2948 KB |
Output is correct |
30 |
Correct |
5 ms |
2948 KB |
Output is correct |
31 |
Correct |
7 ms |
2948 KB |
Output is correct |
32 |
Correct |
5 ms |
2948 KB |
Output is correct |
33 |
Correct |
21 ms |
2948 KB |
Output is correct |
34 |
Correct |
15 ms |
2948 KB |
Output is correct |
35 |
Correct |
15 ms |
2948 KB |
Output is correct |
36 |
Correct |
5 ms |
2948 KB |
Output is correct |
37 |
Correct |
16 ms |
4220 KB |
Output is correct |
38 |
Correct |
14 ms |
4220 KB |
Output is correct |
39 |
Correct |
15 ms |
4220 KB |
Output is correct |
40 |
Correct |
20 ms |
4220 KB |
Output is correct |
41 |
Correct |
19 ms |
4220 KB |
Output is correct |
42 |
Correct |
15 ms |
4220 KB |
Output is correct |
43 |
Correct |
10 ms |
4220 KB |
Output is correct |
44 |
Correct |
15 ms |
4220 KB |
Output is correct |
45 |
Correct |
88 ms |
13332 KB |
Output is correct |
46 |
Correct |
65 ms |
13484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13484 KB |
Output is correct |
2 |
Correct |
4 ms |
13484 KB |
Output is correct |
3 |
Correct |
3 ms |
13484 KB |
Output is correct |
4 |
Correct |
3 ms |
13484 KB |
Output is correct |
5 |
Correct |
3 ms |
13484 KB |
Output is correct |
6 |
Correct |
3 ms |
13484 KB |
Output is correct |
7 |
Correct |
4 ms |
13484 KB |
Output is correct |
8 |
Correct |
3 ms |
13484 KB |
Output is correct |
9 |
Correct |
3 ms |
13484 KB |
Output is correct |
10 |
Correct |
3 ms |
13484 KB |
Output is correct |
11 |
Correct |
3 ms |
13484 KB |
Output is correct |
12 |
Correct |
3 ms |
13484 KB |
Output is correct |
13 |
Correct |
4 ms |
13484 KB |
Output is correct |
14 |
Correct |
5 ms |
13484 KB |
Output is correct |
15 |
Correct |
3 ms |
13484 KB |
Output is correct |
16 |
Correct |
3 ms |
13484 KB |
Output is correct |
17 |
Correct |
5 ms |
13484 KB |
Output is correct |
18 |
Correct |
4 ms |
13484 KB |
Output is correct |
19 |
Correct |
4 ms |
13484 KB |
Output is correct |
20 |
Correct |
4 ms |
13484 KB |
Output is correct |
21 |
Correct |
3 ms |
13484 KB |
Output is correct |
22 |
Correct |
4 ms |
13484 KB |
Output is correct |
23 |
Correct |
5 ms |
13484 KB |
Output is correct |
24 |
Correct |
6 ms |
13484 KB |
Output is correct |
25 |
Correct |
5 ms |
13484 KB |
Output is correct |
26 |
Correct |
4 ms |
13484 KB |
Output is correct |
27 |
Correct |
3 ms |
13484 KB |
Output is correct |
28 |
Correct |
4 ms |
13484 KB |
Output is correct |
29 |
Correct |
13 ms |
13484 KB |
Output is correct |
30 |
Correct |
4 ms |
13484 KB |
Output is correct |
31 |
Correct |
7 ms |
13484 KB |
Output is correct |
32 |
Correct |
7 ms |
13484 KB |
Output is correct |
33 |
Correct |
17 ms |
13484 KB |
Output is correct |
34 |
Correct |
13 ms |
13484 KB |
Output is correct |
35 |
Correct |
14 ms |
13484 KB |
Output is correct |
36 |
Correct |
6 ms |
13484 KB |
Output is correct |
37 |
Correct |
15 ms |
13484 KB |
Output is correct |
38 |
Correct |
15 ms |
13484 KB |
Output is correct |
39 |
Correct |
14 ms |
13484 KB |
Output is correct |
40 |
Correct |
15 ms |
13484 KB |
Output is correct |
41 |
Correct |
17 ms |
13484 KB |
Output is correct |
42 |
Correct |
10 ms |
13484 KB |
Output is correct |
43 |
Correct |
11 ms |
13484 KB |
Output is correct |
44 |
Correct |
9 ms |
13484 KB |
Output is correct |
45 |
Correct |
81 ms |
13484 KB |
Output is correct |
46 |
Correct |
55 ms |
13484 KB |
Output is correct |
47 |
Correct |
32 ms |
13484 KB |
Output is correct |
48 |
Correct |
15 ms |
13484 KB |
Output is correct |
49 |
Correct |
20 ms |
13484 KB |
Output is correct |
50 |
Correct |
10 ms |
13484 KB |
Output is correct |
51 |
Correct |
25 ms |
13484 KB |
Output is correct |
52 |
Correct |
28 ms |
13484 KB |
Output is correct |
53 |
Correct |
11 ms |
13484 KB |
Output is correct |
54 |
Correct |
5 ms |
13484 KB |
Output is correct |
55 |
Correct |
6 ms |
13484 KB |
Output is correct |
56 |
Correct |
15 ms |
13484 KB |
Output is correct |
57 |
Correct |
4 ms |
13484 KB |
Output is correct |
58 |
Correct |
15 ms |
13484 KB |
Output is correct |
59 |
Correct |
13 ms |
13484 KB |
Output is correct |
60 |
Correct |
13 ms |
13484 KB |
Output is correct |
61 |
Correct |
13 ms |
13484 KB |
Output is correct |
62 |
Correct |
32 ms |
13484 KB |
Output is correct |
63 |
Correct |
257 ms |
47900 KB |
Output is correct |
64 |
Correct |
334 ms |
61088 KB |
Output is correct |
65 |
Correct |
760 ms |
71260 KB |
Output is correct |
66 |
Execution timed out |
1081 ms |
86892 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |