#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <deque>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef set < int > si;
const int N = 3e4 + 500;
const int M = 2005;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const int OFF = (1 << LOG);
const double EPS = 1e-9;
const double PI = 3.1415926535;
int dis1[N][M];
gp_hash_table <int, int> dis2[N];
int en, bio[N], x[N], y[N];
int n, m;
vector < int > pot[N];
inline int dis(const int &a,const int &b){
if(b < M) return dis1[a][b];
return dis2[a][b];
}
inline void postavi(const int &a,const int &b,const int &c){
if(b < M) dis1[a][b] = c;
else dis2[a][b] = c;
}
deque < pii > q;
int main(){
scanf("%d%d", &n, &m);
for(int i = 0;i < m;i++){
scanf("%d%d", x + i, y + i);
pot[x[i]].PB(y[i]);
}
postavi(x[0], y[0], 1);
q.push_back({x[0], y[0]});
while(!q.empty()){
int cur = q.front().X;
int sk = q.front().Y;
int moj = dis(cur, sk);
//printf("%d %d = %d\n", cur, sk, dis[cur][sk]);
q.pop_front();
if(!bio[cur]){
for(int x : pot[cur]){
int nw = dis(cur, x);
if((nw == 0 || moj < nw))
q.push_front({cur, x}), postavi(cur, x, moj);
}
}
bio[cur] = 1;
if(cur - sk >= 0){
int nw = dis(cur - sk, sk);
if(nw == 0 || nw > 1 + moj)
q.push_back({cur - sk, sk}), postavi(cur - sk, sk , 1 + moj);
}
if(cur + sk < n){
int nw = dis(cur + sk, sk);
if(nw == 0 || nw > 1 + moj)
q.push_back({cur + sk, sk}), postavi(cur + sk, sk , 1 + moj);
}
}
int ans = INF;
for(int i = 0;i <= n;i++) if(dis(x[1], i)) ans = min(ans, dis(x[1], i));
if(ans == INF) printf("-1\n");
else printf("%d\n", ans - 1);
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", x + i, y + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
7552 KB |
Output is correct |
2 |
Correct |
10 ms |
7424 KB |
Output is correct |
3 |
Correct |
12 ms |
7424 KB |
Output is correct |
4 |
Correct |
10 ms |
7552 KB |
Output is correct |
5 |
Correct |
13 ms |
7552 KB |
Output is correct |
6 |
Correct |
11 ms |
7552 KB |
Output is correct |
7 |
Correct |
11 ms |
7552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
7552 KB |
Output is correct |
2 |
Correct |
27 ms |
7424 KB |
Output is correct |
3 |
Correct |
11 ms |
7524 KB |
Output is correct |
4 |
Correct |
11 ms |
7552 KB |
Output is correct |
5 |
Correct |
12 ms |
7552 KB |
Output is correct |
6 |
Correct |
12 ms |
7552 KB |
Output is correct |
7 |
Correct |
12 ms |
7552 KB |
Output is correct |
8 |
Correct |
12 ms |
7680 KB |
Output is correct |
9 |
Correct |
11 ms |
7680 KB |
Output is correct |
10 |
Correct |
11 ms |
7936 KB |
Output is correct |
11 |
Correct |
13 ms |
7936 KB |
Output is correct |
12 |
Correct |
13 ms |
7936 KB |
Output is correct |
13 |
Correct |
13 ms |
7936 KB |
Output is correct |
14 |
Correct |
12 ms |
7936 KB |
Output is correct |
15 |
Correct |
12 ms |
7936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
7552 KB |
Output is correct |
2 |
Correct |
11 ms |
7576 KB |
Output is correct |
3 |
Correct |
11 ms |
7424 KB |
Output is correct |
4 |
Correct |
11 ms |
7552 KB |
Output is correct |
5 |
Correct |
11 ms |
7552 KB |
Output is correct |
6 |
Correct |
13 ms |
7552 KB |
Output is correct |
7 |
Correct |
13 ms |
7552 KB |
Output is correct |
8 |
Correct |
12 ms |
7680 KB |
Output is correct |
9 |
Correct |
12 ms |
7680 KB |
Output is correct |
10 |
Correct |
11 ms |
7936 KB |
Output is correct |
11 |
Correct |
11 ms |
7964 KB |
Output is correct |
12 |
Correct |
11 ms |
7936 KB |
Output is correct |
13 |
Correct |
11 ms |
7936 KB |
Output is correct |
14 |
Correct |
14 ms |
7936 KB |
Output is correct |
15 |
Correct |
15 ms |
7936 KB |
Output is correct |
16 |
Correct |
13 ms |
7552 KB |
Output is correct |
17 |
Correct |
18 ms |
11520 KB |
Output is correct |
18 |
Correct |
12 ms |
7552 KB |
Output is correct |
19 |
Correct |
13 ms |
7552 KB |
Output is correct |
20 |
Correct |
24 ms |
15608 KB |
Output is correct |
21 |
Correct |
10 ms |
7552 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
20 ms |
16640 KB |
Output is correct |
24 |
Correct |
30 ms |
20224 KB |
Output is correct |
25 |
Correct |
29 ms |
21084 KB |
Output is correct |
26 |
Correct |
21 ms |
16000 KB |
Output is correct |
27 |
Correct |
24 ms |
16636 KB |
Output is correct |
28 |
Correct |
26 ms |
17656 KB |
Output is correct |
29 |
Correct |
23 ms |
15868 KB |
Output is correct |
30 |
Correct |
20 ms |
15744 KB |
Output is correct |
31 |
Correct |
25 ms |
15872 KB |
Output is correct |
32 |
Correct |
22 ms |
16000 KB |
Output is correct |
33 |
Correct |
22 ms |
16040 KB |
Output is correct |
34 |
Correct |
22 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7552 KB |
Output is correct |
2 |
Correct |
11 ms |
7552 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
11 ms |
7552 KB |
Output is correct |
5 |
Correct |
12 ms |
7552 KB |
Output is correct |
6 |
Correct |
14 ms |
7552 KB |
Output is correct |
7 |
Correct |
10 ms |
7552 KB |
Output is correct |
8 |
Correct |
13 ms |
7680 KB |
Output is correct |
9 |
Correct |
10 ms |
7680 KB |
Output is correct |
10 |
Correct |
11 ms |
7936 KB |
Output is correct |
11 |
Correct |
10 ms |
7936 KB |
Output is correct |
12 |
Correct |
12 ms |
7936 KB |
Output is correct |
13 |
Correct |
10 ms |
7936 KB |
Output is correct |
14 |
Correct |
12 ms |
7936 KB |
Output is correct |
15 |
Correct |
12 ms |
7936 KB |
Output is correct |
16 |
Correct |
12 ms |
7552 KB |
Output is correct |
17 |
Correct |
19 ms |
11520 KB |
Output is correct |
18 |
Correct |
14 ms |
7552 KB |
Output is correct |
19 |
Correct |
11 ms |
7552 KB |
Output is correct |
20 |
Correct |
21 ms |
15616 KB |
Output is correct |
21 |
Correct |
13 ms |
7552 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
20 ms |
16500 KB |
Output is correct |
24 |
Correct |
24 ms |
20224 KB |
Output is correct |
25 |
Correct |
26 ms |
20992 KB |
Output is correct |
26 |
Correct |
23 ms |
16000 KB |
Output is correct |
27 |
Correct |
20 ms |
16640 KB |
Output is correct |
28 |
Correct |
24 ms |
17792 KB |
Output is correct |
29 |
Correct |
24 ms |
15872 KB |
Output is correct |
30 |
Correct |
23 ms |
15716 KB |
Output is correct |
31 |
Correct |
20 ms |
15872 KB |
Output is correct |
32 |
Correct |
24 ms |
16000 KB |
Output is correct |
33 |
Correct |
26 ms |
16120 KB |
Output is correct |
34 |
Correct |
24 ms |
15992 KB |
Output is correct |
35 |
Correct |
40 ms |
19324 KB |
Output is correct |
36 |
Correct |
22 ms |
15872 KB |
Output is correct |
37 |
Correct |
45 ms |
22648 KB |
Output is correct |
38 |
Correct |
62 ms |
23928 KB |
Output is correct |
39 |
Correct |
46 ms |
23928 KB |
Output is correct |
40 |
Correct |
54 ms |
23928 KB |
Output is correct |
41 |
Correct |
50 ms |
23928 KB |
Output is correct |
42 |
Correct |
26 ms |
16504 KB |
Output is correct |
43 |
Correct |
35 ms |
17024 KB |
Output is correct |
44 |
Correct |
30 ms |
15992 KB |
Output is correct |
45 |
Correct |
45 ms |
18012 KB |
Output is correct |
46 |
Correct |
40 ms |
18040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
7552 KB |
Output is correct |
2 |
Correct |
11 ms |
7424 KB |
Output is correct |
3 |
Correct |
11 ms |
7552 KB |
Output is correct |
4 |
Correct |
11 ms |
7424 KB |
Output is correct |
5 |
Correct |
11 ms |
7424 KB |
Output is correct |
6 |
Correct |
13 ms |
7552 KB |
Output is correct |
7 |
Correct |
12 ms |
7552 KB |
Output is correct |
8 |
Correct |
13 ms |
7680 KB |
Output is correct |
9 |
Correct |
13 ms |
7808 KB |
Output is correct |
10 |
Correct |
11 ms |
7936 KB |
Output is correct |
11 |
Correct |
12 ms |
7936 KB |
Output is correct |
12 |
Correct |
13 ms |
7936 KB |
Output is correct |
13 |
Correct |
14 ms |
7936 KB |
Output is correct |
14 |
Correct |
13 ms |
7936 KB |
Output is correct |
15 |
Correct |
11 ms |
7936 KB |
Output is correct |
16 |
Correct |
12 ms |
7552 KB |
Output is correct |
17 |
Correct |
16 ms |
11520 KB |
Output is correct |
18 |
Correct |
14 ms |
7552 KB |
Output is correct |
19 |
Correct |
13 ms |
7680 KB |
Output is correct |
20 |
Correct |
18 ms |
15616 KB |
Output is correct |
21 |
Correct |
13 ms |
7552 KB |
Output is correct |
22 |
Correct |
10 ms |
7552 KB |
Output is correct |
23 |
Correct |
26 ms |
16512 KB |
Output is correct |
24 |
Correct |
31 ms |
20188 KB |
Output is correct |
25 |
Correct |
26 ms |
21120 KB |
Output is correct |
26 |
Correct |
24 ms |
16000 KB |
Output is correct |
27 |
Correct |
24 ms |
16760 KB |
Output is correct |
28 |
Correct |
24 ms |
17688 KB |
Output is correct |
29 |
Correct |
23 ms |
15872 KB |
Output is correct |
30 |
Correct |
22 ms |
15736 KB |
Output is correct |
31 |
Correct |
21 ms |
15872 KB |
Output is correct |
32 |
Correct |
21 ms |
15872 KB |
Output is correct |
33 |
Correct |
26 ms |
16120 KB |
Output is correct |
34 |
Correct |
31 ms |
15992 KB |
Output is correct |
35 |
Correct |
36 ms |
19328 KB |
Output is correct |
36 |
Correct |
22 ms |
15864 KB |
Output is correct |
37 |
Correct |
51 ms |
22520 KB |
Output is correct |
38 |
Correct |
52 ms |
23820 KB |
Output is correct |
39 |
Correct |
42 ms |
23928 KB |
Output is correct |
40 |
Correct |
43 ms |
23932 KB |
Output is correct |
41 |
Correct |
44 ms |
23908 KB |
Output is correct |
42 |
Correct |
25 ms |
16504 KB |
Output is correct |
43 |
Correct |
27 ms |
16996 KB |
Output is correct |
44 |
Correct |
27 ms |
15992 KB |
Output is correct |
45 |
Correct |
49 ms |
18144 KB |
Output is correct |
46 |
Correct |
49 ms |
18040 KB |
Output is correct |
47 |
Correct |
250 ms |
106044 KB |
Output is correct |
48 |
Correct |
31 ms |
9460 KB |
Output is correct |
49 |
Correct |
24 ms |
9332 KB |
Output is correct |
50 |
Correct |
27 ms |
9212 KB |
Output is correct |
51 |
Correct |
391 ms |
212472 KB |
Output is correct |
52 |
Correct |
348 ms |
213032 KB |
Output is correct |
53 |
Correct |
178 ms |
130676 KB |
Output is correct |
54 |
Correct |
75 ms |
69364 KB |
Output is correct |
55 |
Correct |
95 ms |
89320 KB |
Output is correct |
56 |
Correct |
157 ms |
130592 KB |
Output is correct |
57 |
Correct |
219 ms |
136180 KB |
Output is correct |
58 |
Correct |
152 ms |
130648 KB |
Output is correct |
59 |
Correct |
177 ms |
132184 KB |
Output is correct |
60 |
Correct |
192 ms |
145396 KB |
Output is correct |
61 |
Correct |
192 ms |
150968 KB |
Output is correct |
62 |
Correct |
365 ms |
225268 KB |
Output is correct |
63 |
Correct |
528 ms |
199612 KB |
Output is correct |
64 |
Correct |
513 ms |
182436 KB |
Output is correct |
65 |
Correct |
555 ms |
170832 KB |
Output is correct |
66 |
Correct |
800 ms |
158664 KB |
Output is correct |
67 |
Correct |
722 ms |
158520 KB |
Output is correct |