#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
const ll mod = 998244353;
//using oset = tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 30020;
ll n, m, dist[maxn], s, t;
vi doges[maxn];
bitset<maxn> hs[maxn];
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
memset(dist, 0x3f, sizeof dist);
cin >> n >> m;
for (int b, p, i = 0; i < m; i++) {
cin >> b >> p;
if(!i) s = b;
if(i==1) t = b;
if(!hs[b].test(p))doges[b].pb(p), hs[b].set(p, 1);
}
priority_queue<pair<int, int>> pq;
dist[s]=0;
pq.push({0, s});
while (!pq.empty()) {
int u, cst;
tie(cst, u) = pq.top();
pq.pop();
cst *= -1;
if (cst > dist[u])
continue;
if(u==t) {
cout << cst << '\n';
return 0;
}
for (auto k : doges[u]) {
for (int v, z =3, i = 1; z&&(u + i * k < n || u - i * k >= 0); i++) {
v = u + i*k;
if(v < n){
if(dist[v] > dist[u] + i) {
dist[v] = dist[u] + i;
pq.push({-dist[v], v});
}
if(hs[v].test(k))
z&=1;
}
v = u - i * k;
if(v >= 0){
if(dist[v] > dist[u] + i) {
dist[v] = dist[u] + i;
pq.push({-dist[v], v});
}
if(hs[v].test(k))
z&=2;
}
}
}
}
cout << -1;
}
Compilation message
skyscraper.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
2 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1348 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
3 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1656 KB |
Output is correct |
11 |
Correct |
5 ms |
1656 KB |
Output is correct |
12 |
Correct |
14 ms |
1276 KB |
Output is correct |
13 |
Correct |
5 ms |
1656 KB |
Output is correct |
14 |
Correct |
5 ms |
1528 KB |
Output is correct |
15 |
Correct |
5 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
3 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1656 KB |
Output is correct |
11 |
Correct |
5 ms |
1656 KB |
Output is correct |
12 |
Correct |
4 ms |
1276 KB |
Output is correct |
13 |
Correct |
4 ms |
1656 KB |
Output is correct |
14 |
Correct |
5 ms |
1528 KB |
Output is correct |
15 |
Correct |
5 ms |
1528 KB |
Output is correct |
16 |
Correct |
5 ms |
2040 KB |
Output is correct |
17 |
Correct |
27 ms |
3832 KB |
Output is correct |
18 |
Correct |
8 ms |
4216 KB |
Output is correct |
19 |
Correct |
5 ms |
3192 KB |
Output is correct |
20 |
Correct |
14 ms |
8696 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
6 ms |
3576 KB |
Output is correct |
23 |
Correct |
8 ms |
4092 KB |
Output is correct |
24 |
Correct |
14 ms |
5880 KB |
Output is correct |
25 |
Correct |
12 ms |
6136 KB |
Output is correct |
26 |
Correct |
7 ms |
1528 KB |
Output is correct |
27 |
Correct |
7 ms |
1532 KB |
Output is correct |
28 |
Correct |
14 ms |
8696 KB |
Output is correct |
29 |
Correct |
8 ms |
1528 KB |
Output is correct |
30 |
Correct |
6 ms |
1528 KB |
Output is correct |
31 |
Correct |
7 ms |
1524 KB |
Output is correct |
32 |
Correct |
7 ms |
1528 KB |
Output is correct |
33 |
Correct |
8 ms |
1656 KB |
Output is correct |
34 |
Correct |
8 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
3 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
8 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1656 KB |
Output is correct |
11 |
Correct |
5 ms |
1656 KB |
Output is correct |
12 |
Correct |
4 ms |
1272 KB |
Output is correct |
13 |
Correct |
5 ms |
1656 KB |
Output is correct |
14 |
Correct |
5 ms |
1528 KB |
Output is correct |
15 |
Correct |
5 ms |
1528 KB |
Output is correct |
16 |
Correct |
4 ms |
2040 KB |
Output is correct |
17 |
Correct |
8 ms |
3832 KB |
Output is correct |
18 |
Correct |
7 ms |
4216 KB |
Output is correct |
19 |
Correct |
6 ms |
3192 KB |
Output is correct |
20 |
Correct |
14 ms |
8696 KB |
Output is correct |
21 |
Correct |
5 ms |
2680 KB |
Output is correct |
22 |
Correct |
6 ms |
3576 KB |
Output is correct |
23 |
Correct |
9 ms |
4088 KB |
Output is correct |
24 |
Correct |
12 ms |
5952 KB |
Output is correct |
25 |
Correct |
12 ms |
6136 KB |
Output is correct |
26 |
Correct |
8 ms |
1656 KB |
Output is correct |
27 |
Correct |
7 ms |
1528 KB |
Output is correct |
28 |
Correct |
14 ms |
8700 KB |
Output is correct |
29 |
Correct |
7 ms |
1528 KB |
Output is correct |
30 |
Correct |
6 ms |
1528 KB |
Output is correct |
31 |
Correct |
15 ms |
1528 KB |
Output is correct |
32 |
Correct |
7 ms |
1656 KB |
Output is correct |
33 |
Correct |
8 ms |
1656 KB |
Output is correct |
34 |
Correct |
8 ms |
1676 KB |
Output is correct |
35 |
Correct |
33 ms |
7032 KB |
Output is correct |
36 |
Correct |
12 ms |
5368 KB |
Output is correct |
37 |
Correct |
29 ms |
8824 KB |
Output is correct |
38 |
Correct |
41 ms |
9120 KB |
Output is correct |
39 |
Correct |
40 ms |
9092 KB |
Output is correct |
40 |
Correct |
48 ms |
9208 KB |
Output is correct |
41 |
Correct |
41 ms |
9080 KB |
Output is correct |
42 |
Correct |
29 ms |
1612 KB |
Output is correct |
43 |
Correct |
28 ms |
1540 KB |
Output is correct |
44 |
Correct |
34 ms |
8696 KB |
Output is correct |
45 |
Correct |
33 ms |
2592 KB |
Output is correct |
46 |
Correct |
31 ms |
2684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1272 KB |
Output is correct |
2 |
Correct |
13 ms |
1272 KB |
Output is correct |
3 |
Correct |
3 ms |
1272 KB |
Output is correct |
4 |
Correct |
3 ms |
1272 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
3 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1276 KB |
Output is correct |
8 |
Correct |
3 ms |
1400 KB |
Output is correct |
9 |
Correct |
3 ms |
1404 KB |
Output is correct |
10 |
Correct |
4 ms |
1656 KB |
Output is correct |
11 |
Correct |
5 ms |
1656 KB |
Output is correct |
12 |
Correct |
5 ms |
1272 KB |
Output is correct |
13 |
Correct |
3 ms |
1656 KB |
Output is correct |
14 |
Correct |
3 ms |
1532 KB |
Output is correct |
15 |
Correct |
5 ms |
1520 KB |
Output is correct |
16 |
Correct |
4 ms |
2052 KB |
Output is correct |
17 |
Correct |
8 ms |
3832 KB |
Output is correct |
18 |
Correct |
7 ms |
4216 KB |
Output is correct |
19 |
Correct |
6 ms |
3228 KB |
Output is correct |
20 |
Correct |
14 ms |
8696 KB |
Output is correct |
21 |
Correct |
5 ms |
2680 KB |
Output is correct |
22 |
Correct |
6 ms |
3576 KB |
Output is correct |
23 |
Correct |
9 ms |
4216 KB |
Output is correct |
24 |
Correct |
12 ms |
5880 KB |
Output is correct |
25 |
Correct |
11 ms |
6136 KB |
Output is correct |
26 |
Correct |
7 ms |
1656 KB |
Output is correct |
27 |
Correct |
7 ms |
1528 KB |
Output is correct |
28 |
Correct |
14 ms |
8696 KB |
Output is correct |
29 |
Correct |
7 ms |
1528 KB |
Output is correct |
30 |
Correct |
6 ms |
1528 KB |
Output is correct |
31 |
Correct |
8 ms |
1528 KB |
Output is correct |
32 |
Correct |
6 ms |
1656 KB |
Output is correct |
33 |
Correct |
8 ms |
1656 KB |
Output is correct |
34 |
Correct |
9 ms |
1784 KB |
Output is correct |
35 |
Correct |
32 ms |
6904 KB |
Output is correct |
36 |
Correct |
12 ms |
5368 KB |
Output is correct |
37 |
Correct |
29 ms |
8824 KB |
Output is correct |
38 |
Correct |
41 ms |
9080 KB |
Output is correct |
39 |
Correct |
39 ms |
9080 KB |
Output is correct |
40 |
Correct |
39 ms |
9208 KB |
Output is correct |
41 |
Correct |
41 ms |
9080 KB |
Output is correct |
42 |
Correct |
28 ms |
1528 KB |
Output is correct |
43 |
Correct |
27 ms |
1528 KB |
Output is correct |
44 |
Correct |
33 ms |
8696 KB |
Output is correct |
45 |
Correct |
31 ms |
2680 KB |
Output is correct |
46 |
Correct |
31 ms |
2700 KB |
Output is correct |
47 |
Correct |
84 ms |
42356 KB |
Output is correct |
48 |
Correct |
98 ms |
57412 KB |
Output is correct |
49 |
Correct |
94 ms |
57592 KB |
Output is correct |
50 |
Correct |
76 ms |
47160 KB |
Output is correct |
51 |
Correct |
159 ms |
76680 KB |
Output is correct |
52 |
Correct |
160 ms |
76148 KB |
Output is correct |
53 |
Correct |
136 ms |
75384 KB |
Output is correct |
54 |
Correct |
23 ms |
1736 KB |
Output is correct |
55 |
Correct |
29 ms |
1784 KB |
Output is correct |
56 |
Correct |
173 ms |
113272 KB |
Output is correct |
57 |
Correct |
58 ms |
11128 KB |
Output is correct |
58 |
Correct |
55 ms |
1912 KB |
Output is correct |
59 |
Correct |
61 ms |
2168 KB |
Output is correct |
60 |
Correct |
63 ms |
2908 KB |
Output is correct |
61 |
Correct |
62 ms |
3672 KB |
Output is correct |
62 |
Correct |
183 ms |
112124 KB |
Output is correct |
63 |
Correct |
115 ms |
5488 KB |
Output is correct |
64 |
Correct |
120 ms |
4860 KB |
Output is correct |
65 |
Correct |
140 ms |
4592 KB |
Output is correct |
66 |
Correct |
187 ms |
5116 KB |
Output is correct |
67 |
Correct |
295 ms |
5212 KB |
Output is correct |