#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
//#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int C = 150;
bool seen[30005][205];
int N, M, st, ed, pos, iq, k, dist[30005][205];
vector<iii> adj[30005][205];
priority_queue<iii, vector<iii>, greater<iii> > pq;
queue<ii> dial[205];
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i < N; i++) {
for (int j = 1; j < C; j++) {
if (i + j < N) adj[i][j].eb(i + j, j, 1);
if (i - j >= 0) adj[i][j].eb(i - j, j, 1);
dist[i][j] = 1e9;
adj[i][j].eb(i, 0, 0);
}
dist[i][0] = 1e9;
}
for (int i = 0, B, P; i < M; i++) {
cin >> B >> P;
if (P >= C) {
for (int j = B + P; j < N; j += P)
adj[B][0].eb(j, 0, (j - B) / P);
for (int j = B - P; j >= 0; j -= P)
adj[B][0].eb(j, 0, (B - j) / P);
} else {
adj[B][0].eb(B, P, 0);
}
if (i == 0) st = B;
else if (i == 1) ed = B;
}
dial[0].emplace(st, 0);
dist[st][0] = 0;
iq = 1;
k = N / C + 1;
while (iq) {
while (dial[pos].empty()) pos = (pos + 1) % (k + 1);
auto [x, y] = dial[pos].front();
dial[pos].pop();
iq--;
if (seen[x][y]) continue;
seen[x][y] = 1;
for (auto [u, v, w] : adj[x][y]) {
if (dist[u][v] > dist[x][y] + w) {
dist[u][v] = dist[x][y] + w;
iq++;
dial[dist[u][v] % (k + 1)].emplace(u, v);
}
}
}
cout << (dist[ed][0] == 1e9 ? -1 : dist[ed][0]) << '\n';
}
Compilation message
skyscraper.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
144928 KB |
Output is correct |
2 |
Correct |
74 ms |
144840 KB |
Output is correct |
3 |
Correct |
74 ms |
144872 KB |
Output is correct |
4 |
Correct |
75 ms |
144868 KB |
Output is correct |
5 |
Correct |
73 ms |
144836 KB |
Output is correct |
6 |
Correct |
73 ms |
144872 KB |
Output is correct |
7 |
Correct |
83 ms |
144856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
144920 KB |
Output is correct |
2 |
Correct |
74 ms |
144852 KB |
Output is correct |
3 |
Correct |
75 ms |
144836 KB |
Output is correct |
4 |
Correct |
74 ms |
144940 KB |
Output is correct |
5 |
Correct |
74 ms |
144916 KB |
Output is correct |
6 |
Correct |
74 ms |
144852 KB |
Output is correct |
7 |
Correct |
74 ms |
144836 KB |
Output is correct |
8 |
Correct |
75 ms |
145104 KB |
Output is correct |
9 |
Correct |
91 ms |
145220 KB |
Output is correct |
10 |
Correct |
76 ms |
145448 KB |
Output is correct |
11 |
Correct |
76 ms |
145544 KB |
Output is correct |
12 |
Correct |
76 ms |
145476 KB |
Output is correct |
13 |
Correct |
77 ms |
145548 KB |
Output is correct |
14 |
Correct |
79 ms |
145540 KB |
Output is correct |
15 |
Correct |
77 ms |
145612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
144916 KB |
Output is correct |
2 |
Correct |
75 ms |
144900 KB |
Output is correct |
3 |
Correct |
81 ms |
144976 KB |
Output is correct |
4 |
Correct |
74 ms |
144908 KB |
Output is correct |
5 |
Correct |
74 ms |
144848 KB |
Output is correct |
6 |
Correct |
78 ms |
144844 KB |
Output is correct |
7 |
Correct |
75 ms |
144852 KB |
Output is correct |
8 |
Correct |
75 ms |
145116 KB |
Output is correct |
9 |
Correct |
76 ms |
145316 KB |
Output is correct |
10 |
Correct |
75 ms |
145440 KB |
Output is correct |
11 |
Correct |
76 ms |
145556 KB |
Output is correct |
12 |
Correct |
75 ms |
145712 KB |
Output is correct |
13 |
Correct |
75 ms |
145588 KB |
Output is correct |
14 |
Correct |
76 ms |
145604 KB |
Output is correct |
15 |
Correct |
79 ms |
145604 KB |
Output is correct |
16 |
Correct |
77 ms |
146244 KB |
Output is correct |
17 |
Correct |
91 ms |
151824 KB |
Output is correct |
18 |
Correct |
111 ms |
161812 KB |
Output is correct |
19 |
Correct |
111 ms |
164420 KB |
Output is correct |
20 |
Correct |
115 ms |
164868 KB |
Output is correct |
21 |
Correct |
82 ms |
148108 KB |
Output is correct |
22 |
Correct |
108 ms |
162248 KB |
Output is correct |
23 |
Correct |
110 ms |
160692 KB |
Output is correct |
24 |
Correct |
114 ms |
163804 KB |
Output is correct |
25 |
Correct |
113 ms |
164904 KB |
Output is correct |
26 |
Correct |
118 ms |
164828 KB |
Output is correct |
27 |
Correct |
112 ms |
164876 KB |
Output is correct |
28 |
Correct |
122 ms |
164892 KB |
Output is correct |
29 |
Correct |
121 ms |
164880 KB |
Output is correct |
30 |
Correct |
113 ms |
164804 KB |
Output is correct |
31 |
Correct |
116 ms |
164800 KB |
Output is correct |
32 |
Correct |
117 ms |
164836 KB |
Output is correct |
33 |
Correct |
132 ms |
164920 KB |
Output is correct |
34 |
Correct |
131 ms |
164932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
144844 KB |
Output is correct |
2 |
Correct |
74 ms |
144836 KB |
Output is correct |
3 |
Correct |
75 ms |
144928 KB |
Output is correct |
4 |
Correct |
77 ms |
144948 KB |
Output is correct |
5 |
Correct |
73 ms |
144844 KB |
Output is correct |
6 |
Correct |
74 ms |
144908 KB |
Output is correct |
7 |
Correct |
74 ms |
144916 KB |
Output is correct |
8 |
Correct |
77 ms |
145056 KB |
Output is correct |
9 |
Correct |
78 ms |
145200 KB |
Output is correct |
10 |
Correct |
75 ms |
145508 KB |
Output is correct |
11 |
Correct |
76 ms |
145588 KB |
Output is correct |
12 |
Correct |
76 ms |
145592 KB |
Output is correct |
13 |
Correct |
76 ms |
145476 KB |
Output is correct |
14 |
Correct |
77 ms |
145600 KB |
Output is correct |
15 |
Correct |
76 ms |
145520 KB |
Output is correct |
16 |
Correct |
77 ms |
146220 KB |
Output is correct |
17 |
Correct |
90 ms |
151864 KB |
Output is correct |
18 |
Correct |
107 ms |
161924 KB |
Output is correct |
19 |
Correct |
113 ms |
164552 KB |
Output is correct |
20 |
Correct |
112 ms |
164868 KB |
Output is correct |
21 |
Correct |
80 ms |
148180 KB |
Output is correct |
22 |
Correct |
106 ms |
162216 KB |
Output is correct |
23 |
Correct |
104 ms |
160656 KB |
Output is correct |
24 |
Correct |
113 ms |
163992 KB |
Output is correct |
25 |
Correct |
114 ms |
164860 KB |
Output is correct |
26 |
Correct |
121 ms |
164856 KB |
Output is correct |
27 |
Correct |
116 ms |
164820 KB |
Output is correct |
28 |
Correct |
118 ms |
164816 KB |
Output is correct |
29 |
Correct |
123 ms |
164940 KB |
Output is correct |
30 |
Correct |
124 ms |
164876 KB |
Output is correct |
31 |
Correct |
116 ms |
164884 KB |
Output is correct |
32 |
Correct |
117 ms |
164808 KB |
Output is correct |
33 |
Correct |
135 ms |
164932 KB |
Output is correct |
34 |
Correct |
134 ms |
164920 KB |
Output is correct |
35 |
Correct |
121 ms |
159556 KB |
Output is correct |
36 |
Correct |
97 ms |
155460 KB |
Output is correct |
37 |
Correct |
139 ms |
165404 KB |
Output is correct |
38 |
Correct |
143 ms |
165848 KB |
Output is correct |
39 |
Correct |
141 ms |
165864 KB |
Output is correct |
40 |
Correct |
143 ms |
165912 KB |
Output is correct |
41 |
Correct |
140 ms |
165904 KB |
Output is correct |
42 |
Correct |
117 ms |
165356 KB |
Output is correct |
43 |
Correct |
116 ms |
165300 KB |
Output is correct |
44 |
Correct |
118 ms |
165248 KB |
Output is correct |
45 |
Correct |
164 ms |
168168 KB |
Output is correct |
46 |
Correct |
164 ms |
168004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
144900 KB |
Output is correct |
2 |
Correct |
74 ms |
144864 KB |
Output is correct |
3 |
Correct |
74 ms |
144876 KB |
Output is correct |
4 |
Correct |
74 ms |
144876 KB |
Output is correct |
5 |
Correct |
74 ms |
144836 KB |
Output is correct |
6 |
Correct |
74 ms |
144888 KB |
Output is correct |
7 |
Correct |
74 ms |
144836 KB |
Output is correct |
8 |
Correct |
75 ms |
145092 KB |
Output is correct |
9 |
Correct |
74 ms |
145196 KB |
Output is correct |
10 |
Correct |
74 ms |
145496 KB |
Output is correct |
11 |
Correct |
78 ms |
145528 KB |
Output is correct |
12 |
Correct |
78 ms |
145596 KB |
Output is correct |
13 |
Correct |
76 ms |
145496 KB |
Output is correct |
14 |
Correct |
76 ms |
145604 KB |
Output is correct |
15 |
Correct |
79 ms |
145548 KB |
Output is correct |
16 |
Correct |
76 ms |
146232 KB |
Output is correct |
17 |
Correct |
90 ms |
151804 KB |
Output is correct |
18 |
Correct |
105 ms |
161860 KB |
Output is correct |
19 |
Correct |
111 ms |
164460 KB |
Output is correct |
20 |
Correct |
114 ms |
164940 KB |
Output is correct |
21 |
Correct |
81 ms |
148236 KB |
Output is correct |
22 |
Correct |
108 ms |
162244 KB |
Output is correct |
23 |
Correct |
111 ms |
160708 KB |
Output is correct |
24 |
Correct |
115 ms |
163908 KB |
Output is correct |
25 |
Correct |
114 ms |
164876 KB |
Output is correct |
26 |
Correct |
119 ms |
164864 KB |
Output is correct |
27 |
Correct |
115 ms |
164888 KB |
Output is correct |
28 |
Correct |
116 ms |
164888 KB |
Output is correct |
29 |
Correct |
121 ms |
164780 KB |
Output is correct |
30 |
Correct |
114 ms |
164780 KB |
Output is correct |
31 |
Correct |
116 ms |
164812 KB |
Output is correct |
32 |
Correct |
117 ms |
164880 KB |
Output is correct |
33 |
Correct |
135 ms |
164932 KB |
Output is correct |
34 |
Correct |
134 ms |
164884 KB |
Output is correct |
35 |
Correct |
118 ms |
159588 KB |
Output is correct |
36 |
Correct |
95 ms |
155504 KB |
Output is correct |
37 |
Correct |
145 ms |
165436 KB |
Output is correct |
38 |
Correct |
139 ms |
165800 KB |
Output is correct |
39 |
Correct |
155 ms |
165864 KB |
Output is correct |
40 |
Correct |
139 ms |
166084 KB |
Output is correct |
41 |
Correct |
144 ms |
165952 KB |
Output is correct |
42 |
Correct |
116 ms |
165364 KB |
Output is correct |
43 |
Correct |
125 ms |
165256 KB |
Output is correct |
44 |
Correct |
114 ms |
165272 KB |
Output is correct |
45 |
Correct |
166 ms |
168032 KB |
Output is correct |
46 |
Correct |
166 ms |
167908 KB |
Output is correct |
47 |
Runtime error |
268 ms |
262148 KB |
Execution killed with signal 9 |
48 |
Halted |
0 ms |
0 KB |
- |