#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
const int N = 3e4 + 4;
const int kok = 177;
typedef long long ll;
typedef pair < int , int > pp;
vector < pp > Q[N*kok];
vector < int > V[N];
int H[N][kok],F[N],beg[N],jum[N],n,m,i,j,x,u,res,ss;
void f(int x, int u, int t){
if(u >= kok){
for(int i=0;i<kok;i++){
if(x + i*u < n && !H[x+i*u][0])
ss++, Q[t+i].pb(mp(x+i*u,0));
if(x - i*u >= 0 && !H[x-i*u][0])
ss++, Q[t+i].pb(mp(x-i*u,0));
}
}
else if(!H[x][u]) ss++, Q[t].pb(mp(x,u));
}
int main(){
cin >> n >> m;
for(i=0;i<m;i++){
scanf("%d%d",&beg[i],&jum[i]);
V[ beg[i] ].pb( jum[i] );
}
f(beg[0],jum[0],0);
for(res=0 ; ss ; res++)
for(i=0;i<Q[res].size();i++,ss--){
x = Q[res][i].st;
u = Q[res][i].nd;
if(x == beg[1]) { cout << res; return 0; }
if(H[x][u]) continue;
H[x][u] = 1;
if(u){ if(x+u<n && !H[x+u][u])ss++,Q[res+1].pb(mp(x+u,u));
if(x-u>=0 && !H[x-u][u])ss++,Q[res+1].pb(mp(x-u,u)); }
if(F[x]) continue;
F[x] = 1;
for(j=0;j<V[x].size();j++)
f(x,V[x][j],res);
}
cout << -1;
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<Q[res].size();i++,ss--){
~^~~~~~~~~~~~~~
skyscraper.cpp:49:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<V[x].size();j++)
~^~~~~~~~~~~~
skyscraper.cpp:38:1: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(res=0 ; ss ; res++)
^~~
skyscraper.cpp:53:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
cout << -1;
^~~~
skyscraper.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&beg[i],&jum[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
125780 KB |
Output is correct |
2 |
Correct |
97 ms |
125824 KB |
Output is correct |
3 |
Correct |
98 ms |
125856 KB |
Output is correct |
4 |
Correct |
98 ms |
125856 KB |
Output is correct |
5 |
Correct |
97 ms |
125916 KB |
Output is correct |
6 |
Correct |
102 ms |
126032 KB |
Output is correct |
7 |
Correct |
100 ms |
126032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
126032 KB |
Output is correct |
2 |
Correct |
100 ms |
126032 KB |
Output is correct |
3 |
Correct |
99 ms |
126032 KB |
Output is correct |
4 |
Correct |
98 ms |
126032 KB |
Output is correct |
5 |
Correct |
99 ms |
126032 KB |
Output is correct |
6 |
Correct |
106 ms |
126032 KB |
Output is correct |
7 |
Correct |
102 ms |
126032 KB |
Output is correct |
8 |
Correct |
100 ms |
126032 KB |
Output is correct |
9 |
Correct |
101 ms |
126040 KB |
Output is correct |
10 |
Correct |
120 ms |
126052 KB |
Output is correct |
11 |
Correct |
102 ms |
126112 KB |
Output is correct |
12 |
Correct |
100 ms |
126112 KB |
Output is correct |
13 |
Correct |
99 ms |
126144 KB |
Output is correct |
14 |
Correct |
105 ms |
126184 KB |
Output is correct |
15 |
Correct |
100 ms |
126184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
126184 KB |
Output is correct |
2 |
Correct |
101 ms |
126184 KB |
Output is correct |
3 |
Correct |
103 ms |
126184 KB |
Output is correct |
4 |
Correct |
97 ms |
126184 KB |
Output is correct |
5 |
Correct |
99 ms |
126184 KB |
Output is correct |
6 |
Correct |
100 ms |
126184 KB |
Output is correct |
7 |
Correct |
108 ms |
126184 KB |
Output is correct |
8 |
Correct |
99 ms |
126184 KB |
Output is correct |
9 |
Correct |
100 ms |
126184 KB |
Output is correct |
10 |
Correct |
100 ms |
126184 KB |
Output is correct |
11 |
Correct |
100 ms |
126184 KB |
Output is correct |
12 |
Correct |
102 ms |
126184 KB |
Output is correct |
13 |
Correct |
102 ms |
126184 KB |
Output is correct |
14 |
Correct |
100 ms |
126184 KB |
Output is correct |
15 |
Correct |
99 ms |
126184 KB |
Output is correct |
16 |
Correct |
104 ms |
126184 KB |
Output is correct |
17 |
Correct |
99 ms |
126588 KB |
Output is correct |
18 |
Correct |
100 ms |
126588 KB |
Output is correct |
19 |
Correct |
100 ms |
126588 KB |
Output is correct |
20 |
Correct |
103 ms |
127616 KB |
Output is correct |
21 |
Correct |
100 ms |
127616 KB |
Output is correct |
22 |
Correct |
100 ms |
127616 KB |
Output is correct |
23 |
Correct |
104 ms |
127616 KB |
Output is correct |
24 |
Correct |
103 ms |
127616 KB |
Output is correct |
25 |
Correct |
101 ms |
127616 KB |
Output is correct |
26 |
Correct |
107 ms |
127616 KB |
Output is correct |
27 |
Correct |
106 ms |
127616 KB |
Output is correct |
28 |
Correct |
114 ms |
127956 KB |
Output is correct |
29 |
Correct |
103 ms |
128124 KB |
Output is correct |
30 |
Correct |
108 ms |
128124 KB |
Output is correct |
31 |
Correct |
104 ms |
128124 KB |
Output is correct |
32 |
Correct |
113 ms |
128124 KB |
Output is correct |
33 |
Correct |
109 ms |
128636 KB |
Output is correct |
34 |
Correct |
106 ms |
128636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
128636 KB |
Output is correct |
2 |
Correct |
99 ms |
128636 KB |
Output is correct |
3 |
Correct |
112 ms |
128636 KB |
Output is correct |
4 |
Correct |
109 ms |
128636 KB |
Output is correct |
5 |
Correct |
105 ms |
128636 KB |
Output is correct |
6 |
Correct |
104 ms |
128636 KB |
Output is correct |
7 |
Correct |
109 ms |
128636 KB |
Output is correct |
8 |
Correct |
102 ms |
128636 KB |
Output is correct |
9 |
Correct |
100 ms |
128636 KB |
Output is correct |
10 |
Correct |
102 ms |
128636 KB |
Output is correct |
11 |
Correct |
108 ms |
128636 KB |
Output is correct |
12 |
Correct |
108 ms |
128636 KB |
Output is correct |
13 |
Correct |
123 ms |
128636 KB |
Output is correct |
14 |
Correct |
101 ms |
128636 KB |
Output is correct |
15 |
Correct |
106 ms |
128636 KB |
Output is correct |
16 |
Correct |
102 ms |
128636 KB |
Output is correct |
17 |
Correct |
108 ms |
128636 KB |
Output is correct |
18 |
Correct |
104 ms |
128636 KB |
Output is correct |
19 |
Correct |
114 ms |
128636 KB |
Output is correct |
20 |
Correct |
102 ms |
128636 KB |
Output is correct |
21 |
Correct |
101 ms |
128636 KB |
Output is correct |
22 |
Correct |
101 ms |
128636 KB |
Output is correct |
23 |
Correct |
104 ms |
128636 KB |
Output is correct |
24 |
Correct |
111 ms |
128636 KB |
Output is correct |
25 |
Correct |
101 ms |
128636 KB |
Output is correct |
26 |
Correct |
101 ms |
128636 KB |
Output is correct |
27 |
Correct |
108 ms |
128636 KB |
Output is correct |
28 |
Correct |
120 ms |
128636 KB |
Output is correct |
29 |
Correct |
107 ms |
128636 KB |
Output is correct |
30 |
Correct |
121 ms |
128636 KB |
Output is correct |
31 |
Correct |
104 ms |
128636 KB |
Output is correct |
32 |
Correct |
103 ms |
128636 KB |
Output is correct |
33 |
Correct |
119 ms |
128636 KB |
Output is correct |
34 |
Correct |
105 ms |
128636 KB |
Output is correct |
35 |
Correct |
121 ms |
128636 KB |
Output is correct |
36 |
Correct |
117 ms |
128636 KB |
Output is correct |
37 |
Correct |
109 ms |
128636 KB |
Output is correct |
38 |
Correct |
115 ms |
128636 KB |
Output is correct |
39 |
Correct |
120 ms |
128636 KB |
Output is correct |
40 |
Correct |
121 ms |
128636 KB |
Output is correct |
41 |
Correct |
118 ms |
128636 KB |
Output is correct |
42 |
Correct |
108 ms |
128636 KB |
Output is correct |
43 |
Correct |
107 ms |
128636 KB |
Output is correct |
44 |
Correct |
109 ms |
128636 KB |
Output is correct |
45 |
Correct |
129 ms |
132272 KB |
Output is correct |
46 |
Correct |
139 ms |
132272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
132272 KB |
Output is correct |
2 |
Correct |
112 ms |
132272 KB |
Output is correct |
3 |
Correct |
112 ms |
132272 KB |
Output is correct |
4 |
Correct |
106 ms |
132272 KB |
Output is correct |
5 |
Correct |
106 ms |
132272 KB |
Output is correct |
6 |
Correct |
108 ms |
132272 KB |
Output is correct |
7 |
Correct |
109 ms |
132272 KB |
Output is correct |
8 |
Correct |
100 ms |
132272 KB |
Output is correct |
9 |
Correct |
109 ms |
132272 KB |
Output is correct |
10 |
Correct |
102 ms |
132272 KB |
Output is correct |
11 |
Correct |
120 ms |
132272 KB |
Output is correct |
12 |
Correct |
106 ms |
132272 KB |
Output is correct |
13 |
Correct |
105 ms |
132272 KB |
Output is correct |
14 |
Correct |
115 ms |
132272 KB |
Output is correct |
15 |
Correct |
118 ms |
132272 KB |
Output is correct |
16 |
Correct |
103 ms |
132272 KB |
Output is correct |
17 |
Correct |
111 ms |
132272 KB |
Output is correct |
18 |
Correct |
104 ms |
132272 KB |
Output is correct |
19 |
Correct |
121 ms |
132272 KB |
Output is correct |
20 |
Correct |
124 ms |
132272 KB |
Output is correct |
21 |
Correct |
106 ms |
132272 KB |
Output is correct |
22 |
Correct |
106 ms |
132272 KB |
Output is correct |
23 |
Correct |
109 ms |
132272 KB |
Output is correct |
24 |
Correct |
107 ms |
132272 KB |
Output is correct |
25 |
Correct |
107 ms |
132272 KB |
Output is correct |
26 |
Correct |
110 ms |
132272 KB |
Output is correct |
27 |
Correct |
104 ms |
132272 KB |
Output is correct |
28 |
Correct |
116 ms |
132272 KB |
Output is correct |
29 |
Correct |
123 ms |
132272 KB |
Output is correct |
30 |
Correct |
118 ms |
132272 KB |
Output is correct |
31 |
Correct |
126 ms |
132272 KB |
Output is correct |
32 |
Correct |
121 ms |
132272 KB |
Output is correct |
33 |
Correct |
113 ms |
132272 KB |
Output is correct |
34 |
Correct |
111 ms |
132272 KB |
Output is correct |
35 |
Correct |
119 ms |
132272 KB |
Output is correct |
36 |
Correct |
105 ms |
132272 KB |
Output is correct |
37 |
Correct |
119 ms |
132272 KB |
Output is correct |
38 |
Correct |
122 ms |
132272 KB |
Output is correct |
39 |
Correct |
118 ms |
132272 KB |
Output is correct |
40 |
Correct |
115 ms |
132272 KB |
Output is correct |
41 |
Correct |
117 ms |
132272 KB |
Output is correct |
42 |
Correct |
114 ms |
132272 KB |
Output is correct |
43 |
Correct |
112 ms |
132272 KB |
Output is correct |
44 |
Correct |
112 ms |
132272 KB |
Output is correct |
45 |
Correct |
132 ms |
132272 KB |
Output is correct |
46 |
Correct |
125 ms |
132272 KB |
Output is correct |
47 |
Correct |
123 ms |
134780 KB |
Output is correct |
48 |
Correct |
110 ms |
134780 KB |
Output is correct |
49 |
Correct |
113 ms |
134780 KB |
Output is correct |
50 |
Correct |
112 ms |
134780 KB |
Output is correct |
51 |
Correct |
156 ms |
148092 KB |
Output is correct |
52 |
Correct |
147 ms |
148348 KB |
Output is correct |
53 |
Correct |
118 ms |
148348 KB |
Output is correct |
54 |
Correct |
122 ms |
148348 KB |
Output is correct |
55 |
Correct |
122 ms |
148348 KB |
Output is correct |
56 |
Correct |
144 ms |
149100 KB |
Output is correct |
57 |
Correct |
113 ms |
149100 KB |
Output is correct |
58 |
Correct |
139 ms |
149408 KB |
Output is correct |
59 |
Correct |
136 ms |
149408 KB |
Output is correct |
60 |
Correct |
144 ms |
149408 KB |
Output is correct |
61 |
Correct |
137 ms |
149408 KB |
Output is correct |
62 |
Correct |
190 ms |
156028 KB |
Output is correct |
63 |
Correct |
200 ms |
157944 KB |
Output is correct |
64 |
Correct |
200 ms |
159300 KB |
Output is correct |
65 |
Correct |
279 ms |
177556 KB |
Output is correct |
66 |
Correct |
399 ms |
210612 KB |
Output is correct |
67 |
Correct |
266 ms |
210612 KB |
Output is correct |