#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;
priority_queue < pair < int , pp > > Q;
vector < int > V[N];
int H[N][kok],F[N],beg[N],jum[N],n,m,i,x,u,res;
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])
Q.push(mp(t-i,mp(x+i*u,0)));
if(x - i*u >= 0 && !H[x-i*u][0])
Q.push(mp(t-i,mp(x-i*u,0)));
}
}
else if(!H[x][u]) Q.push(mp(t,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(; Q.size() ;){
x = Q.top().nd.st;
u = Q.top().nd.nd;
res = Q.top().st;
Q.pop();
// cout << x << " " << u << " " << res << " ss\n";
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])Q.push(mp(res-1,mp(x+u,u))); if(x-u>=0 && !H[x-u][u])Q.push(mp(res-1,mp(x-u,u))); }
if(F[x]) continue;
F[x] = 1;
for(i=0;i<V[x].size();i++)
f(x,V[x][i],res);
}
cout << -1;
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<V[x].size();i++)
~^~~~~~~~~~~~
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 |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1124 KB |
Output is correct |
3 |
Correct |
2 ms |
1176 KB |
Output is correct |
4 |
Correct |
2 ms |
1176 KB |
Output is correct |
5 |
Correct |
3 ms |
1284 KB |
Output is correct |
6 |
Correct |
2 ms |
1284 KB |
Output is correct |
7 |
Correct |
3 ms |
1284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1284 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
3 ms |
1388 KB |
Output is correct |
5 |
Correct |
3 ms |
1388 KB |
Output is correct |
6 |
Correct |
3 ms |
1388 KB |
Output is correct |
7 |
Correct |
2 ms |
1388 KB |
Output is correct |
8 |
Correct |
3 ms |
1388 KB |
Output is correct |
9 |
Correct |
2 ms |
1388 KB |
Output is correct |
10 |
Correct |
3 ms |
1404 KB |
Output is correct |
11 |
Correct |
3 ms |
1408 KB |
Output is correct |
12 |
Correct |
3 ms |
1408 KB |
Output is correct |
13 |
Correct |
3 ms |
1408 KB |
Output is correct |
14 |
Correct |
5 ms |
1408 KB |
Output is correct |
15 |
Correct |
4 ms |
1444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1444 KB |
Output is correct |
2 |
Correct |
2 ms |
1444 KB |
Output is correct |
3 |
Correct |
3 ms |
1444 KB |
Output is correct |
4 |
Correct |
2 ms |
1444 KB |
Output is correct |
5 |
Correct |
2 ms |
1444 KB |
Output is correct |
6 |
Correct |
2 ms |
1444 KB |
Output is correct |
7 |
Correct |
2 ms |
1444 KB |
Output is correct |
8 |
Correct |
2 ms |
1444 KB |
Output is correct |
9 |
Correct |
2 ms |
1444 KB |
Output is correct |
10 |
Correct |
3 ms |
1444 KB |
Output is correct |
11 |
Correct |
3 ms |
1444 KB |
Output is correct |
12 |
Correct |
4 ms |
1444 KB |
Output is correct |
13 |
Correct |
3 ms |
1444 KB |
Output is correct |
14 |
Correct |
5 ms |
1444 KB |
Output is correct |
15 |
Correct |
3 ms |
1444 KB |
Output is correct |
16 |
Correct |
2 ms |
1444 KB |
Output is correct |
17 |
Correct |
4 ms |
1916 KB |
Output is correct |
18 |
Correct |
2 ms |
1916 KB |
Output is correct |
19 |
Correct |
3 ms |
1916 KB |
Output is correct |
20 |
Correct |
6 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
3 ms |
2816 KB |
Output is correct |
23 |
Correct |
5 ms |
2816 KB |
Output is correct |
24 |
Correct |
6 ms |
2816 KB |
Output is correct |
25 |
Correct |
4 ms |
2816 KB |
Output is correct |
26 |
Correct |
4 ms |
2816 KB |
Output is correct |
27 |
Correct |
4 ms |
2816 KB |
Output is correct |
28 |
Correct |
5 ms |
2816 KB |
Output is correct |
29 |
Correct |
11 ms |
2816 KB |
Output is correct |
30 |
Correct |
5 ms |
2816 KB |
Output is correct |
31 |
Correct |
8 ms |
2816 KB |
Output is correct |
32 |
Correct |
7 ms |
2816 KB |
Output is correct |
33 |
Correct |
22 ms |
2816 KB |
Output is correct |
34 |
Correct |
15 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2816 KB |
Output is correct |
2 |
Correct |
2 ms |
2816 KB |
Output is correct |
3 |
Correct |
2 ms |
2816 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
2 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2816 KB |
Output is correct |
10 |
Correct |
3 ms |
2816 KB |
Output is correct |
11 |
Correct |
4 ms |
2816 KB |
Output is correct |
12 |
Correct |
4 ms |
2816 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
5 ms |
2816 KB |
Output is correct |
15 |
Correct |
5 ms |
2816 KB |
Output is correct |
16 |
Correct |
4 ms |
2816 KB |
Output is correct |
17 |
Correct |
4 ms |
2816 KB |
Output is correct |
18 |
Correct |
3 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
4 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
4 ms |
2816 KB |
Output is correct |
24 |
Correct |
6 ms |
2816 KB |
Output is correct |
25 |
Correct |
5 ms |
2816 KB |
Output is correct |
26 |
Correct |
4 ms |
2816 KB |
Output is correct |
27 |
Correct |
4 ms |
2816 KB |
Output is correct |
28 |
Correct |
5 ms |
2816 KB |
Output is correct |
29 |
Correct |
13 ms |
2816 KB |
Output is correct |
30 |
Correct |
5 ms |
2816 KB |
Output is correct |
31 |
Correct |
8 ms |
2816 KB |
Output is correct |
32 |
Correct |
8 ms |
2816 KB |
Output is correct |
33 |
Correct |
22 ms |
2816 KB |
Output is correct |
34 |
Correct |
13 ms |
2816 KB |
Output is correct |
35 |
Correct |
23 ms |
3004 KB |
Output is correct |
36 |
Correct |
5 ms |
3004 KB |
Output is correct |
37 |
Correct |
12 ms |
3132 KB |
Output is correct |
38 |
Correct |
28 ms |
3572 KB |
Output is correct |
39 |
Correct |
11 ms |
3572 KB |
Output is correct |
40 |
Correct |
16 ms |
3572 KB |
Output is correct |
41 |
Correct |
27 ms |
3624 KB |
Output is correct |
42 |
Correct |
9 ms |
3624 KB |
Output is correct |
43 |
Correct |
10 ms |
3624 KB |
Output is correct |
44 |
Correct |
9 ms |
3624 KB |
Output is correct |
45 |
Correct |
113 ms |
5100 KB |
Output is correct |
46 |
Correct |
76 ms |
5104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5104 KB |
Output is correct |
2 |
Correct |
3 ms |
5104 KB |
Output is correct |
3 |
Correct |
3 ms |
5104 KB |
Output is correct |
4 |
Correct |
2 ms |
5104 KB |
Output is correct |
5 |
Correct |
2 ms |
5104 KB |
Output is correct |
6 |
Correct |
2 ms |
5104 KB |
Output is correct |
7 |
Correct |
2 ms |
5104 KB |
Output is correct |
8 |
Correct |
2 ms |
5104 KB |
Output is correct |
9 |
Correct |
2 ms |
5104 KB |
Output is correct |
10 |
Correct |
3 ms |
5104 KB |
Output is correct |
11 |
Correct |
3 ms |
5104 KB |
Output is correct |
12 |
Correct |
3 ms |
5104 KB |
Output is correct |
13 |
Correct |
3 ms |
5104 KB |
Output is correct |
14 |
Correct |
4 ms |
5104 KB |
Output is correct |
15 |
Correct |
3 ms |
5104 KB |
Output is correct |
16 |
Correct |
3 ms |
5104 KB |
Output is correct |
17 |
Correct |
4 ms |
5104 KB |
Output is correct |
18 |
Correct |
3 ms |
5104 KB |
Output is correct |
19 |
Correct |
3 ms |
5104 KB |
Output is correct |
20 |
Correct |
4 ms |
5104 KB |
Output is correct |
21 |
Correct |
2 ms |
5104 KB |
Output is correct |
22 |
Correct |
4 ms |
5104 KB |
Output is correct |
23 |
Correct |
6 ms |
5104 KB |
Output is correct |
24 |
Correct |
7 ms |
5104 KB |
Output is correct |
25 |
Correct |
4 ms |
5104 KB |
Output is correct |
26 |
Correct |
5 ms |
5104 KB |
Output is correct |
27 |
Correct |
6 ms |
5104 KB |
Output is correct |
28 |
Correct |
6 ms |
5104 KB |
Output is correct |
29 |
Correct |
11 ms |
5104 KB |
Output is correct |
30 |
Correct |
6 ms |
5104 KB |
Output is correct |
31 |
Correct |
8 ms |
5104 KB |
Output is correct |
32 |
Correct |
8 ms |
5104 KB |
Output is correct |
33 |
Correct |
27 ms |
5104 KB |
Output is correct |
34 |
Correct |
17 ms |
5104 KB |
Output is correct |
35 |
Correct |
21 ms |
5104 KB |
Output is correct |
36 |
Correct |
6 ms |
5104 KB |
Output is correct |
37 |
Correct |
12 ms |
5104 KB |
Output is correct |
38 |
Correct |
28 ms |
5104 KB |
Output is correct |
39 |
Correct |
11 ms |
5104 KB |
Output is correct |
40 |
Correct |
13 ms |
5104 KB |
Output is correct |
41 |
Correct |
30 ms |
5104 KB |
Output is correct |
42 |
Correct |
13 ms |
5104 KB |
Output is correct |
43 |
Correct |
16 ms |
5104 KB |
Output is correct |
44 |
Correct |
11 ms |
5104 KB |
Output is correct |
45 |
Correct |
112 ms |
5104 KB |
Output is correct |
46 |
Correct |
79 ms |
5104 KB |
Output is correct |
47 |
Correct |
22 ms |
7536 KB |
Output is correct |
48 |
Correct |
11 ms |
7536 KB |
Output is correct |
49 |
Correct |
11 ms |
7536 KB |
Output is correct |
50 |
Correct |
8 ms |
7536 KB |
Output is correct |
51 |
Correct |
51 ms |
23288 KB |
Output is correct |
52 |
Correct |
64 ms |
23568 KB |
Output is correct |
53 |
Correct |
21 ms |
23568 KB |
Output is correct |
54 |
Correct |
24 ms |
23568 KB |
Output is correct |
55 |
Correct |
25 ms |
23568 KB |
Output is correct |
56 |
Correct |
36 ms |
23568 KB |
Output is correct |
57 |
Correct |
4 ms |
23568 KB |
Output is correct |
58 |
Correct |
41 ms |
23568 KB |
Output is correct |
59 |
Correct |
35 ms |
23568 KB |
Output is correct |
60 |
Correct |
35 ms |
23568 KB |
Output is correct |
61 |
Correct |
36 ms |
23568 KB |
Output is correct |
62 |
Correct |
82 ms |
23568 KB |
Output is correct |
63 |
Correct |
453 ms |
33100 KB |
Output is correct |
64 |
Correct |
538 ms |
33708 KB |
Output is correct |
65 |
Execution timed out |
1087 ms |
42812 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |