#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const int mxN = 3e4 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
int n, m, pos[mxN], dist[mxN], len[mxN]; vi nodes[mxN]; bool done[mxN];
priority_queue<pii, vpii, greater<pii>> pq;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
memset(len, 0x3f, sizeof(len));
F0R(i, m){
cin >> pos[i] >> dist[i];
nodes[pos[i]].pb(dist[i]);
}
int F = pos[0], S = pos[1];
len[pos[0]] = 0;
pq.push({0, pos[0]});
while(!pq.empty()){
pii x = pq.top(); pq.pop();
// cout << x.f << " " << x.s << endl;
if(x.f!=len[x.s]) continue;
if(x.s == S) break;
trav(speed, nodes[x.s]){
int p = x.s + speed;
for(int i = 1; p < n; i++, p+=speed){
if(ckmin(len[p], x.f+i)){
pq.push({len[p], p});
}
}
p = x.s - speed;
for(int i = 1; p >= 0; i++, p-=speed){
if(ckmin(len[p], x.f+i)){
pq.push({len[p], p});
}
}
}
}
cout << (len[S]>=MOD?-1:len[S]) << nl;
return 0;
}
Compilation message
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:42:9: warning: unused variable 'F' [-Wunused-variable]
42 | int F = pos[0], S = pos[1];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1152 KB |
Output is correct |
8 |
Correct |
1 ms |
1152 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Correct |
1 ms |
1152 KB |
Output is correct |
11 |
Correct |
1 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
1 ms |
1152 KB |
Output is correct |
14 |
Correct |
2 ms |
1152 KB |
Output is correct |
15 |
Correct |
1 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1152 KB |
Output is correct |
8 |
Correct |
1 ms |
1152 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Correct |
1 ms |
1152 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
1 ms |
1152 KB |
Output is correct |
14 |
Correct |
1 ms |
1152 KB |
Output is correct |
15 |
Correct |
1 ms |
1152 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1280 KB |
Output is correct |
18 |
Correct |
1 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
1152 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 KB |
Output is correct |
22 |
Correct |
2 ms |
1152 KB |
Output is correct |
23 |
Correct |
1 ms |
1280 KB |
Output is correct |
24 |
Correct |
2 ms |
1280 KB |
Output is correct |
25 |
Correct |
1 ms |
1280 KB |
Output is correct |
26 |
Correct |
2 ms |
1152 KB |
Output is correct |
27 |
Correct |
2 ms |
1152 KB |
Output is correct |
28 |
Correct |
2 ms |
1280 KB |
Output is correct |
29 |
Correct |
3 ms |
1408 KB |
Output is correct |
30 |
Correct |
2 ms |
1280 KB |
Output is correct |
31 |
Correct |
2 ms |
1280 KB |
Output is correct |
32 |
Correct |
2 ms |
1280 KB |
Output is correct |
33 |
Correct |
3 ms |
1408 KB |
Output is correct |
34 |
Correct |
3 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1152 KB |
Output is correct |
8 |
Correct |
1 ms |
1152 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Correct |
1 ms |
1152 KB |
Output is correct |
11 |
Correct |
1 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
2 ms |
1152 KB |
Output is correct |
14 |
Correct |
1 ms |
1152 KB |
Output is correct |
15 |
Correct |
1 ms |
1152 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1280 KB |
Output is correct |
18 |
Correct |
1 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
1152 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
1152 KB |
Output is correct |
23 |
Correct |
2 ms |
1280 KB |
Output is correct |
24 |
Correct |
2 ms |
1312 KB |
Output is correct |
25 |
Correct |
2 ms |
1280 KB |
Output is correct |
26 |
Correct |
2 ms |
1152 KB |
Output is correct |
27 |
Correct |
2 ms |
1152 KB |
Output is correct |
28 |
Correct |
2 ms |
1280 KB |
Output is correct |
29 |
Correct |
3 ms |
1408 KB |
Output is correct |
30 |
Correct |
2 ms |
1280 KB |
Output is correct |
31 |
Correct |
2 ms |
1280 KB |
Output is correct |
32 |
Correct |
2 ms |
1280 KB |
Output is correct |
33 |
Correct |
3 ms |
1408 KB |
Output is correct |
34 |
Correct |
3 ms |
1408 KB |
Output is correct |
35 |
Correct |
8 ms |
1664 KB |
Output is correct |
36 |
Correct |
2 ms |
1280 KB |
Output is correct |
37 |
Correct |
6 ms |
1664 KB |
Output is correct |
38 |
Correct |
9 ms |
1792 KB |
Output is correct |
39 |
Correct |
7 ms |
1664 KB |
Output is correct |
40 |
Correct |
8 ms |
1664 KB |
Output is correct |
41 |
Correct |
8 ms |
1792 KB |
Output is correct |
42 |
Correct |
6 ms |
1664 KB |
Output is correct |
43 |
Correct |
6 ms |
1664 KB |
Output is correct |
44 |
Correct |
68 ms |
1664 KB |
Output is correct |
45 |
Correct |
8 ms |
1792 KB |
Output is correct |
46 |
Correct |
9 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1152 KB |
Output is correct |
8 |
Correct |
1 ms |
1152 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Correct |
1 ms |
1152 KB |
Output is correct |
11 |
Correct |
1 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
2 ms |
1152 KB |
Output is correct |
14 |
Correct |
1 ms |
1152 KB |
Output is correct |
15 |
Correct |
1 ms |
1152 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1280 KB |
Output is correct |
18 |
Correct |
1 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
1152 KB |
Output is correct |
20 |
Correct |
6 ms |
1280 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
1152 KB |
Output is correct |
23 |
Correct |
2 ms |
1280 KB |
Output is correct |
24 |
Correct |
2 ms |
1280 KB |
Output is correct |
25 |
Correct |
2 ms |
1280 KB |
Output is correct |
26 |
Correct |
2 ms |
1152 KB |
Output is correct |
27 |
Correct |
2 ms |
1152 KB |
Output is correct |
28 |
Correct |
2 ms |
1280 KB |
Output is correct |
29 |
Correct |
3 ms |
1408 KB |
Output is correct |
30 |
Correct |
2 ms |
1280 KB |
Output is correct |
31 |
Correct |
2 ms |
1280 KB |
Output is correct |
32 |
Correct |
2 ms |
1280 KB |
Output is correct |
33 |
Correct |
4 ms |
1408 KB |
Output is correct |
34 |
Correct |
3 ms |
1408 KB |
Output is correct |
35 |
Correct |
7 ms |
1664 KB |
Output is correct |
36 |
Correct |
2 ms |
1280 KB |
Output is correct |
37 |
Correct |
6 ms |
1664 KB |
Output is correct |
38 |
Correct |
8 ms |
1792 KB |
Output is correct |
39 |
Correct |
7 ms |
1664 KB |
Output is correct |
40 |
Correct |
8 ms |
1664 KB |
Output is correct |
41 |
Correct |
8 ms |
1792 KB |
Output is correct |
42 |
Correct |
6 ms |
1664 KB |
Output is correct |
43 |
Correct |
6 ms |
1664 KB |
Output is correct |
44 |
Correct |
70 ms |
1664 KB |
Output is correct |
45 |
Correct |
9 ms |
1920 KB |
Output is correct |
46 |
Correct |
8 ms |
1792 KB |
Output is correct |
47 |
Correct |
11 ms |
2300 KB |
Output is correct |
48 |
Correct |
7 ms |
1792 KB |
Output is correct |
49 |
Correct |
8 ms |
1792 KB |
Output is correct |
50 |
Correct |
5 ms |
1664 KB |
Output is correct |
51 |
Correct |
18 ms |
3192 KB |
Output is correct |
52 |
Correct |
17 ms |
2684 KB |
Output is correct |
53 |
Correct |
11 ms |
2304 KB |
Output is correct |
54 |
Correct |
2 ms |
1408 KB |
Output is correct |
55 |
Correct |
3 ms |
1408 KB |
Output is correct |
56 |
Correct |
910 ms |
2688 KB |
Output is correct |
57 |
Correct |
3 ms |
1912 KB |
Output is correct |
58 |
Correct |
858 ms |
1804 KB |
Output is correct |
59 |
Correct |
8 ms |
1792 KB |
Output is correct |
60 |
Correct |
8 ms |
1792 KB |
Output is correct |
61 |
Correct |
8 ms |
1792 KB |
Output is correct |
62 |
Correct |
11 ms |
2304 KB |
Output is correct |
63 |
Correct |
34 ms |
2808 KB |
Output is correct |
64 |
Correct |
35 ms |
3828 KB |
Output is correct |
65 |
Correct |
42 ms |
3828 KB |
Output is correct |
66 |
Correct |
60 ms |
3828 KB |
Output is correct |
67 |
Correct |
46 ms |
3828 KB |
Output is correct |