#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){
int i;
if(u > kok){
for(i=0;i<kok;i++){
if(x + i*u < n)
Q.push(mp(t-i,mp(x+i*u,0)));
if(x - i*u >= 0)
Q.push(mp(t-i,mp(x-i*u,0)));
}
}
else 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)Q.push(mp(res-1,mp(x+u,u))); if(x-u>=0)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:51:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<V[x].size();i++)
~^~~~~~~~~~~~
skyscraper.cpp:34: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]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
1132 KB |
Output is correct |
3 |
Correct |
3 ms |
1132 KB |
Output is correct |
4 |
Correct |
2 ms |
1132 KB |
Output is correct |
5 |
Correct |
2 ms |
1176 KB |
Output is correct |
6 |
Correct |
2 ms |
1436 KB |
Output is correct |
7 |
Correct |
2 ms |
1436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1436 KB |
Output is correct |
2 |
Correct |
2 ms |
1436 KB |
Output is correct |
3 |
Correct |
2 ms |
1436 KB |
Output is correct |
4 |
Correct |
2 ms |
1436 KB |
Output is correct |
5 |
Correct |
2 ms |
1436 KB |
Output is correct |
6 |
Correct |
2 ms |
1436 KB |
Output is correct |
7 |
Correct |
2 ms |
1436 KB |
Output is correct |
8 |
Correct |
3 ms |
1436 KB |
Output is correct |
9 |
Correct |
2 ms |
1440 KB |
Output is correct |
10 |
Correct |
3 ms |
1448 KB |
Output is correct |
11 |
Correct |
3 ms |
1452 KB |
Output is correct |
12 |
Correct |
3 ms |
1472 KB |
Output is correct |
13 |
Correct |
3 ms |
1484 KB |
Output is correct |
14 |
Correct |
5 ms |
1624 KB |
Output is correct |
15 |
Correct |
3 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1624 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
2 ms |
1624 KB |
Output is correct |
5 |
Correct |
3 ms |
1624 KB |
Output is correct |
6 |
Correct |
2 ms |
1624 KB |
Output is correct |
7 |
Correct |
3 ms |
1624 KB |
Output is correct |
8 |
Correct |
2 ms |
1624 KB |
Output is correct |
9 |
Correct |
2 ms |
1624 KB |
Output is correct |
10 |
Correct |
3 ms |
1624 KB |
Output is correct |
11 |
Correct |
3 ms |
1624 KB |
Output is correct |
12 |
Correct |
3 ms |
1624 KB |
Output is correct |
13 |
Correct |
3 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
1736 KB |
Output is correct |
15 |
Correct |
3 ms |
1736 KB |
Output is correct |
16 |
Correct |
2 ms |
1736 KB |
Output is correct |
17 |
Correct |
4 ms |
2148 KB |
Output is correct |
18 |
Correct |
3 ms |
2148 KB |
Output is correct |
19 |
Correct |
2 ms |
2148 KB |
Output is correct |
20 |
Correct |
4 ms |
3024 KB |
Output is correct |
21 |
Correct |
3 ms |
3024 KB |
Output is correct |
22 |
Correct |
2 ms |
3024 KB |
Output is correct |
23 |
Correct |
5 ms |
3024 KB |
Output is correct |
24 |
Correct |
6 ms |
3024 KB |
Output is correct |
25 |
Correct |
4 ms |
3024 KB |
Output is correct |
26 |
Correct |
4 ms |
3024 KB |
Output is correct |
27 |
Correct |
4 ms |
3024 KB |
Output is correct |
28 |
Correct |
6 ms |
3048 KB |
Output is correct |
29 |
Correct |
22 ms |
3048 KB |
Output is correct |
30 |
Correct |
18 ms |
3048 KB |
Output is correct |
31 |
Correct |
13 ms |
3048 KB |
Output is correct |
32 |
Correct |
10 ms |
3048 KB |
Output is correct |
33 |
Correct |
40 ms |
3080 KB |
Output is correct |
34 |
Correct |
24 ms |
3080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3080 KB |
Output is correct |
2 |
Correct |
2 ms |
3080 KB |
Output is correct |
3 |
Correct |
2 ms |
3080 KB |
Output is correct |
4 |
Correct |
2 ms |
3080 KB |
Output is correct |
5 |
Correct |
2 ms |
3080 KB |
Output is correct |
6 |
Correct |
2 ms |
3080 KB |
Output is correct |
7 |
Correct |
2 ms |
3080 KB |
Output is correct |
8 |
Correct |
2 ms |
3080 KB |
Output is correct |
9 |
Correct |
2 ms |
3080 KB |
Output is correct |
10 |
Correct |
3 ms |
3080 KB |
Output is correct |
11 |
Correct |
3 ms |
3080 KB |
Output is correct |
12 |
Correct |
3 ms |
3080 KB |
Output is correct |
13 |
Correct |
3 ms |
3080 KB |
Output is correct |
14 |
Correct |
4 ms |
3080 KB |
Output is correct |
15 |
Correct |
5 ms |
3080 KB |
Output is correct |
16 |
Correct |
2 ms |
3080 KB |
Output is correct |
17 |
Correct |
4 ms |
3080 KB |
Output is correct |
18 |
Correct |
3 ms |
3080 KB |
Output is correct |
19 |
Correct |
3 ms |
3080 KB |
Output is correct |
20 |
Correct |
4 ms |
3080 KB |
Output is correct |
21 |
Correct |
3 ms |
3080 KB |
Output is correct |
22 |
Correct |
3 ms |
3080 KB |
Output is correct |
23 |
Correct |
5 ms |
3080 KB |
Output is correct |
24 |
Correct |
6 ms |
3080 KB |
Output is correct |
25 |
Correct |
4 ms |
3080 KB |
Output is correct |
26 |
Correct |
4 ms |
3080 KB |
Output is correct |
27 |
Correct |
4 ms |
3080 KB |
Output is correct |
28 |
Correct |
6 ms |
3080 KB |
Output is correct |
29 |
Correct |
21 ms |
3080 KB |
Output is correct |
30 |
Correct |
8 ms |
3080 KB |
Output is correct |
31 |
Correct |
13 ms |
3080 KB |
Output is correct |
32 |
Correct |
10 ms |
3080 KB |
Output is correct |
33 |
Correct |
41 ms |
3188 KB |
Output is correct |
34 |
Correct |
33 ms |
3188 KB |
Output is correct |
35 |
Correct |
23 ms |
3396 KB |
Output is correct |
36 |
Correct |
5 ms |
3396 KB |
Output is correct |
37 |
Correct |
13 ms |
3396 KB |
Output is correct |
38 |
Correct |
30 ms |
4180 KB |
Output is correct |
39 |
Correct |
11 ms |
4180 KB |
Output is correct |
40 |
Correct |
14 ms |
4180 KB |
Output is correct |
41 |
Correct |
28 ms |
4208 KB |
Output is correct |
42 |
Correct |
9 ms |
4208 KB |
Output is correct |
43 |
Correct |
9 ms |
4208 KB |
Output is correct |
44 |
Correct |
13 ms |
4208 KB |
Output is correct |
45 |
Correct |
182 ms |
5304 KB |
Output is correct |
46 |
Correct |
109 ms |
5600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5600 KB |
Output is correct |
2 |
Correct |
2 ms |
5600 KB |
Output is correct |
3 |
Correct |
3 ms |
5600 KB |
Output is correct |
4 |
Correct |
3 ms |
5600 KB |
Output is correct |
5 |
Correct |
2 ms |
5600 KB |
Output is correct |
6 |
Correct |
2 ms |
5600 KB |
Output is correct |
7 |
Correct |
3 ms |
5600 KB |
Output is correct |
8 |
Correct |
2 ms |
5600 KB |
Output is correct |
9 |
Correct |
2 ms |
5600 KB |
Output is correct |
10 |
Correct |
3 ms |
5600 KB |
Output is correct |
11 |
Correct |
3 ms |
5600 KB |
Output is correct |
12 |
Correct |
3 ms |
5600 KB |
Output is correct |
13 |
Correct |
3 ms |
5600 KB |
Output is correct |
14 |
Correct |
5 ms |
5600 KB |
Output is correct |
15 |
Correct |
3 ms |
5600 KB |
Output is correct |
16 |
Correct |
3 ms |
5600 KB |
Output is correct |
17 |
Correct |
4 ms |
5600 KB |
Output is correct |
18 |
Correct |
3 ms |
5600 KB |
Output is correct |
19 |
Correct |
3 ms |
5600 KB |
Output is correct |
20 |
Correct |
4 ms |
5600 KB |
Output is correct |
21 |
Correct |
3 ms |
5600 KB |
Output is correct |
22 |
Correct |
2 ms |
5600 KB |
Output is correct |
23 |
Correct |
5 ms |
5600 KB |
Output is correct |
24 |
Correct |
6 ms |
5600 KB |
Output is correct |
25 |
Correct |
5 ms |
5600 KB |
Output is correct |
26 |
Correct |
5 ms |
5600 KB |
Output is correct |
27 |
Correct |
5 ms |
5600 KB |
Output is correct |
28 |
Correct |
6 ms |
5600 KB |
Output is correct |
29 |
Correct |
22 ms |
5600 KB |
Output is correct |
30 |
Correct |
8 ms |
5600 KB |
Output is correct |
31 |
Correct |
13 ms |
5600 KB |
Output is correct |
32 |
Correct |
12 ms |
5600 KB |
Output is correct |
33 |
Correct |
42 ms |
5600 KB |
Output is correct |
34 |
Correct |
25 ms |
5600 KB |
Output is correct |
35 |
Correct |
23 ms |
5600 KB |
Output is correct |
36 |
Correct |
5 ms |
5600 KB |
Output is correct |
37 |
Correct |
13 ms |
5600 KB |
Output is correct |
38 |
Correct |
36 ms |
5600 KB |
Output is correct |
39 |
Correct |
11 ms |
5600 KB |
Output is correct |
40 |
Correct |
14 ms |
5600 KB |
Output is correct |
41 |
Correct |
29 ms |
5600 KB |
Output is correct |
42 |
Correct |
9 ms |
5600 KB |
Output is correct |
43 |
Correct |
9 ms |
5600 KB |
Output is correct |
44 |
Correct |
12 ms |
5600 KB |
Output is correct |
45 |
Correct |
190 ms |
5620 KB |
Output is correct |
46 |
Correct |
105 ms |
5872 KB |
Output is correct |
47 |
Correct |
21 ms |
8532 KB |
Output is correct |
48 |
Correct |
10 ms |
8532 KB |
Output is correct |
49 |
Correct |
14 ms |
8532 KB |
Output is correct |
50 |
Correct |
8 ms |
8532 KB |
Output is correct |
51 |
Correct |
56 ms |
25504 KB |
Output is correct |
52 |
Correct |
65 ms |
26156 KB |
Output is correct |
53 |
Correct |
31 ms |
26156 KB |
Output is correct |
54 |
Correct |
25 ms |
26156 KB |
Output is correct |
55 |
Correct |
32 ms |
26156 KB |
Output is correct |
56 |
Correct |
38 ms |
26296 KB |
Output is correct |
57 |
Correct |
4 ms |
26296 KB |
Output is correct |
58 |
Correct |
46 ms |
26296 KB |
Output is correct |
59 |
Correct |
37 ms |
26296 KB |
Output is correct |
60 |
Correct |
37 ms |
26296 KB |
Output is correct |
61 |
Correct |
37 ms |
26472 KB |
Output is correct |
62 |
Correct |
96 ms |
27484 KB |
Output is correct |
63 |
Correct |
890 ms |
37876 KB |
Output is correct |
64 |
Execution timed out |
1076 ms |
38360 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |