#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 547
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ld pai=acos(-1);
int n , m , sta , en ;
vpi v[30009] ;
unordered_set<int>s[30009];
int dis[30009] ;
int main () {
scanf("%d%d",&n,&m);
for ( int i = 0 ; i < m ; i ++ ) {
int pos , x ;
scanf("%d%d",&pos,&x);
if ( i == 0 ) sta = pos ;
if ( i == 1 ) en = pos ;
s[pos].ins ( x ) ;
}
for ( int i = 0 ; i < n ; i ++ ) {
dis [i] = 1e9 ;
for ( auto u : s[i] ) {
int len = 0 ;
for ( int j = i + u ; j < n ; j += u ) {
len ++ ;
v[i].pb ( { j , len } ) ;
if ( s[j] .count ( u ) ) break ;
}
len = 0 ;
for ( int j = i - u ; j >= 0 ; j -= u ) {
len ++ ;
v[i].pb ( { j , len } ) ;
if ( s[j] .count ( u ) ) break ;
}
}
}
priority_queue< pair<int , int> , vector< pair<int , int> > , greater< pair<int , int> > > st ;
dis [sta] = 0 ;
st .push ( { 0 , sta } ) ;
while ( st.size() ) {
int node = st.top().se;
int t = st.top().fi;
st .pop();
if ( node == en ) {
printf("%d\n",t);
exit(0);
}
if ( t > dis[node] ) C ;
for ( auto U : v[node] ) {
int u = U.fi ;
int x = U.se ;
if ( t + x < dis [u] ) {
dis [u] = t + x ;
st.push ( { dis[u] , u } ) ;
}
}
}
printf("-1\n");
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:37:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&pos,&x);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
7 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2720 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
7 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
6 ms |
2816 KB |
Output is correct |
17 |
Correct |
8 ms |
2944 KB |
Output is correct |
18 |
Correct |
6 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2816 KB |
Output is correct |
20 |
Correct |
7 ms |
2944 KB |
Output is correct |
21 |
Correct |
7 ms |
2816 KB |
Output is correct |
22 |
Correct |
7 ms |
2816 KB |
Output is correct |
23 |
Correct |
7 ms |
2816 KB |
Output is correct |
24 |
Correct |
8 ms |
2944 KB |
Output is correct |
25 |
Correct |
7 ms |
2944 KB |
Output is correct |
26 |
Correct |
7 ms |
2816 KB |
Output is correct |
27 |
Correct |
7 ms |
2816 KB |
Output is correct |
28 |
Correct |
8 ms |
3072 KB |
Output is correct |
29 |
Correct |
10 ms |
3584 KB |
Output is correct |
30 |
Correct |
7 ms |
3072 KB |
Output is correct |
31 |
Correct |
8 ms |
3200 KB |
Output is correct |
32 |
Correct |
7 ms |
3072 KB |
Output is correct |
33 |
Correct |
10 ms |
4096 KB |
Output is correct |
34 |
Correct |
10 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
7 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2816 KB |
Output is correct |
17 |
Correct |
7 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
7 ms |
2816 KB |
Output is correct |
20 |
Correct |
7 ms |
2944 KB |
Output is correct |
21 |
Correct |
7 ms |
2728 KB |
Output is correct |
22 |
Correct |
7 ms |
2816 KB |
Output is correct |
23 |
Correct |
7 ms |
2816 KB |
Output is correct |
24 |
Correct |
8 ms |
2944 KB |
Output is correct |
25 |
Correct |
8 ms |
2944 KB |
Output is correct |
26 |
Correct |
7 ms |
2816 KB |
Output is correct |
27 |
Correct |
7 ms |
2816 KB |
Output is correct |
28 |
Correct |
8 ms |
3072 KB |
Output is correct |
29 |
Correct |
9 ms |
3584 KB |
Output is correct |
30 |
Correct |
7 ms |
2944 KB |
Output is correct |
31 |
Correct |
8 ms |
3072 KB |
Output is correct |
32 |
Correct |
7 ms |
3072 KB |
Output is correct |
33 |
Correct |
11 ms |
4096 KB |
Output is correct |
34 |
Correct |
10 ms |
4096 KB |
Output is correct |
35 |
Correct |
23 ms |
5120 KB |
Output is correct |
36 |
Correct |
9 ms |
3072 KB |
Output is correct |
37 |
Correct |
24 ms |
5760 KB |
Output is correct |
38 |
Correct |
29 ms |
6008 KB |
Output is correct |
39 |
Correct |
29 ms |
6144 KB |
Output is correct |
40 |
Correct |
28 ms |
6016 KB |
Output is correct |
41 |
Correct |
28 ms |
6016 KB |
Output is correct |
42 |
Correct |
12 ms |
2944 KB |
Output is correct |
43 |
Correct |
12 ms |
2944 KB |
Output is correct |
44 |
Correct |
12 ms |
3072 KB |
Output is correct |
45 |
Correct |
29 ms |
8448 KB |
Output is correct |
46 |
Correct |
28 ms |
8576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
6 ms |
2688 KB |
Output is correct |
10 |
Correct |
6 ms |
2688 KB |
Output is correct |
11 |
Correct |
7 ms |
2816 KB |
Output is correct |
12 |
Correct |
8 ms |
2688 KB |
Output is correct |
13 |
Correct |
7 ms |
2688 KB |
Output is correct |
14 |
Correct |
7 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
7 ms |
2688 KB |
Output is correct |
17 |
Correct |
8 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2816 KB |
Output is correct |
19 |
Correct |
6 ms |
2816 KB |
Output is correct |
20 |
Correct |
7 ms |
2816 KB |
Output is correct |
21 |
Correct |
7 ms |
2688 KB |
Output is correct |
22 |
Correct |
7 ms |
2944 KB |
Output is correct |
23 |
Correct |
7 ms |
2816 KB |
Output is correct |
24 |
Correct |
8 ms |
2944 KB |
Output is correct |
25 |
Correct |
7 ms |
2944 KB |
Output is correct |
26 |
Correct |
7 ms |
2816 KB |
Output is correct |
27 |
Correct |
7 ms |
2816 KB |
Output is correct |
28 |
Correct |
8 ms |
3072 KB |
Output is correct |
29 |
Correct |
9 ms |
3584 KB |
Output is correct |
30 |
Correct |
7 ms |
3072 KB |
Output is correct |
31 |
Correct |
8 ms |
3200 KB |
Output is correct |
32 |
Correct |
7 ms |
3072 KB |
Output is correct |
33 |
Correct |
10 ms |
4096 KB |
Output is correct |
34 |
Correct |
10 ms |
4096 KB |
Output is correct |
35 |
Correct |
23 ms |
5120 KB |
Output is correct |
36 |
Correct |
9 ms |
3072 KB |
Output is correct |
37 |
Correct |
24 ms |
5760 KB |
Output is correct |
38 |
Correct |
28 ms |
6016 KB |
Output is correct |
39 |
Correct |
28 ms |
6016 KB |
Output is correct |
40 |
Correct |
28 ms |
6008 KB |
Output is correct |
41 |
Correct |
28 ms |
6016 KB |
Output is correct |
42 |
Correct |
11 ms |
2944 KB |
Output is correct |
43 |
Correct |
12 ms |
3072 KB |
Output is correct |
44 |
Correct |
12 ms |
3072 KB |
Output is correct |
45 |
Correct |
28 ms |
8448 KB |
Output is correct |
46 |
Correct |
28 ms |
8576 KB |
Output is correct |
47 |
Correct |
56 ms |
13308 KB |
Output is correct |
48 |
Correct |
32 ms |
6516 KB |
Output is correct |
49 |
Correct |
31 ms |
5880 KB |
Output is correct |
50 |
Correct |
19 ms |
5376 KB |
Output is correct |
51 |
Correct |
45 ms |
8796 KB |
Output is correct |
52 |
Correct |
45 ms |
9208 KB |
Output is correct |
53 |
Correct |
25 ms |
5756 KB |
Output is correct |
54 |
Correct |
8 ms |
3328 KB |
Output is correct |
55 |
Correct |
20 ms |
3708 KB |
Output is correct |
56 |
Correct |
28 ms |
5888 KB |
Output is correct |
57 |
Correct |
24 ms |
11648 KB |
Output is correct |
58 |
Correct |
16 ms |
3960 KB |
Output is correct |
59 |
Correct |
16 ms |
4348 KB |
Output is correct |
60 |
Correct |
19 ms |
4988 KB |
Output is correct |
61 |
Correct |
17 ms |
4480 KB |
Output is correct |
62 |
Correct |
40 ms |
10100 KB |
Output is correct |
63 |
Correct |
92 ms |
25844 KB |
Output is correct |
64 |
Correct |
96 ms |
29092 KB |
Output is correct |
65 |
Correct |
124 ms |
39788 KB |
Output is correct |
66 |
Correct |
185 ms |
65380 KB |
Output is correct |
67 |
Correct |
178 ms |
65508 KB |
Output is correct |