#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#define INF 1000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#ifdef wiwihorz
#define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a)
void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
#define x first
#define y second
namespace solver {
int n, m, s, t, ii;
const int P = 200, mx = 8000000;
vector<pii> mp[mx], a;
vector<int> v[P + 1][P + 1];
vector<int> dis;
void init_(int _n, int _m) {
ii = _n;
n = _n, m = _m;
a.clear();
dis.assign(mx, INF);
}
void solve() {
for(auto i : a) {
int st = i.y % i.x;
for(int j = st; j < n; j += i.x) {
ii++;
if(j != st) mp[ii].push_back({ii - 1, 1});
if(j + i.x < n) mp[ii].push_back({ii + 1, 1});
if(j == i.y) mp[j].push_back({ii, 0});
mp[ii].push_back({j, 0});
}
}
rep(i, 1, P) rep(j, 0, i - 1) {
sort(all(v[i][j]));
if(!v[i][j].size()) continue;
int cur = 0;
for(int k = j; k < n; k += i) {
ii++;
if(k != j) mp[ii].push_back({ii - 1, 1});
if(k + i < n) mp[ii].push_back({ii + 1, 1});
if(cur < v[i][j].size() &&
v[i][j][cur] == k) mp[k].push_back({ii, 0}), cur++;
mp[ii].push_back({k, 0});
}
}
dis[s] = 0;
deque<int> q;
q.push_back(s);
while(q.size()) {
int cur = q.front();
q.pop_front();
if(cur == t) {
cout << dis[cur] << "\n";
return;
}
for(auto i : mp[cur]) {
if(dis[i.x] != INF) continue;
dis[i.x] = dis[cur] + i.y;
if(i.y) q.push_back(i.x);
else q.push_front(i.x);
}
}
cout << "-1\n";
return;
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, m;
cin >> n >> m;
init_(n, m);
rep(i, 0, m - 1) {
int b, p;
cin >> b >> p;
if(i == 0) s = b;
if(i == 1) t = b;
if(p <= P) v[p][b % p].push_back(b);
else a.push_back({p, b});
}
solve();
return 0;
}
Compilation message
skyscraper.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
5 | #pragma loop-opt(on)
|
skyscraper.cpp:19:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
| ^~~~
skyscraper.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
19 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
| ^~~~
skyscraper.cpp: In function 'void solver::solve()':
skyscraper.cpp:59:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if(cur < v[i][j].size() &&
| ~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
220352 KB |
Output is correct |
2 |
Correct |
97 ms |
220336 KB |
Output is correct |
3 |
Correct |
98 ms |
220404 KB |
Output is correct |
4 |
Correct |
97 ms |
220424 KB |
Output is correct |
5 |
Correct |
107 ms |
220396 KB |
Output is correct |
6 |
Correct |
105 ms |
220372 KB |
Output is correct |
7 |
Correct |
96 ms |
220424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
220376 KB |
Output is correct |
2 |
Correct |
99 ms |
220380 KB |
Output is correct |
3 |
Correct |
102 ms |
220364 KB |
Output is correct |
4 |
Correct |
98 ms |
220400 KB |
Output is correct |
5 |
Correct |
99 ms |
220412 KB |
Output is correct |
6 |
Correct |
97 ms |
220400 KB |
Output is correct |
7 |
Correct |
99 ms |
220316 KB |
Output is correct |
8 |
Correct |
97 ms |
220364 KB |
Output is correct |
9 |
Correct |
109 ms |
220432 KB |
Output is correct |
10 |
Correct |
101 ms |
220460 KB |
Output is correct |
11 |
Correct |
100 ms |
220640 KB |
Output is correct |
12 |
Correct |
108 ms |
220444 KB |
Output is correct |
13 |
Correct |
98 ms |
220384 KB |
Output is correct |
14 |
Correct |
98 ms |
220712 KB |
Output is correct |
15 |
Correct |
104 ms |
220740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
220364 KB |
Output is correct |
2 |
Correct |
99 ms |
220312 KB |
Output is correct |
3 |
Correct |
103 ms |
220344 KB |
Output is correct |
4 |
Correct |
100 ms |
220316 KB |
Output is correct |
5 |
Correct |
99 ms |
220384 KB |
Output is correct |
6 |
Correct |
101 ms |
220352 KB |
Output is correct |
7 |
Correct |
106 ms |
220404 KB |
Output is correct |
8 |
Correct |
102 ms |
220376 KB |
Output is correct |
9 |
Correct |
104 ms |
220380 KB |
Output is correct |
10 |
Correct |
99 ms |
220468 KB |
Output is correct |
11 |
Correct |
99 ms |
220620 KB |
Output is correct |
12 |
Correct |
98 ms |
220384 KB |
Output is correct |
13 |
Correct |
100 ms |
220408 KB |
Output is correct |
14 |
Correct |
99 ms |
220808 KB |
Output is correct |
15 |
Correct |
100 ms |
220660 KB |
Output is correct |
16 |
Correct |
98 ms |
220572 KB |
Output is correct |
17 |
Correct |
99 ms |
221120 KB |
Output is correct |
18 |
Correct |
99 ms |
220644 KB |
Output is correct |
19 |
Correct |
99 ms |
220648 KB |
Output is correct |
20 |
Correct |
99 ms |
220572 KB |
Output is correct |
21 |
Correct |
102 ms |
220544 KB |
Output is correct |
22 |
Correct |
100 ms |
220716 KB |
Output is correct |
23 |
Correct |
98 ms |
220704 KB |
Output is correct |
24 |
Correct |
100 ms |
220936 KB |
Output is correct |
25 |
Correct |
100 ms |
220688 KB |
Output is correct |
26 |
Correct |
101 ms |
220732 KB |
Output is correct |
27 |
Correct |
99 ms |
220748 KB |
Output is correct |
28 |
Correct |
101 ms |
221496 KB |
Output is correct |
29 |
Correct |
107 ms |
223260 KB |
Output is correct |
30 |
Correct |
112 ms |
221256 KB |
Output is correct |
31 |
Correct |
107 ms |
221932 KB |
Output is correct |
32 |
Correct |
101 ms |
221536 KB |
Output is correct |
33 |
Correct |
119 ms |
225984 KB |
Output is correct |
34 |
Correct |
129 ms |
225996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
220412 KB |
Output is correct |
2 |
Correct |
100 ms |
220340 KB |
Output is correct |
3 |
Correct |
99 ms |
220320 KB |
Output is correct |
4 |
Correct |
97 ms |
220368 KB |
Output is correct |
5 |
Correct |
98 ms |
220364 KB |
Output is correct |
6 |
Correct |
98 ms |
220344 KB |
Output is correct |
7 |
Correct |
100 ms |
220320 KB |
Output is correct |
8 |
Correct |
100 ms |
220332 KB |
Output is correct |
9 |
Correct |
98 ms |
220440 KB |
Output is correct |
10 |
Correct |
111 ms |
220432 KB |
Output is correct |
11 |
Correct |
104 ms |
220664 KB |
Output is correct |
12 |
Correct |
100 ms |
220388 KB |
Output is correct |
13 |
Correct |
100 ms |
220348 KB |
Output is correct |
14 |
Correct |
100 ms |
220636 KB |
Output is correct |
15 |
Correct |
100 ms |
220648 KB |
Output is correct |
16 |
Correct |
104 ms |
220612 KB |
Output is correct |
17 |
Correct |
103 ms |
221084 KB |
Output is correct |
18 |
Correct |
103 ms |
220744 KB |
Output is correct |
19 |
Correct |
100 ms |
220580 KB |
Output is correct |
20 |
Correct |
107 ms |
220588 KB |
Output is correct |
21 |
Correct |
110 ms |
220456 KB |
Output is correct |
22 |
Correct |
99 ms |
220608 KB |
Output is correct |
23 |
Correct |
98 ms |
220748 KB |
Output is correct |
24 |
Correct |
100 ms |
220972 KB |
Output is correct |
25 |
Correct |
100 ms |
220760 KB |
Output is correct |
26 |
Correct |
100 ms |
220776 KB |
Output is correct |
27 |
Correct |
110 ms |
220700 KB |
Output is correct |
28 |
Correct |
102 ms |
221460 KB |
Output is correct |
29 |
Correct |
107 ms |
223304 KB |
Output is correct |
30 |
Correct |
100 ms |
221160 KB |
Output is correct |
31 |
Correct |
104 ms |
221948 KB |
Output is correct |
32 |
Correct |
101 ms |
221520 KB |
Output is correct |
33 |
Correct |
118 ms |
226020 KB |
Output is correct |
34 |
Correct |
115 ms |
226024 KB |
Output is correct |
35 |
Correct |
129 ms |
225300 KB |
Output is correct |
36 |
Correct |
102 ms |
221272 KB |
Output is correct |
37 |
Correct |
125 ms |
228556 KB |
Output is correct |
38 |
Correct |
125 ms |
227892 KB |
Output is correct |
39 |
Correct |
118 ms |
227828 KB |
Output is correct |
40 |
Correct |
120 ms |
227868 KB |
Output is correct |
41 |
Correct |
132 ms |
227892 KB |
Output is correct |
42 |
Correct |
104 ms |
220868 KB |
Output is correct |
43 |
Correct |
101 ms |
220976 KB |
Output is correct |
44 |
Correct |
103 ms |
220620 KB |
Output is correct |
45 |
Correct |
230 ms |
243188 KB |
Output is correct |
46 |
Correct |
203 ms |
243192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
220432 KB |
Output is correct |
2 |
Correct |
108 ms |
220408 KB |
Output is correct |
3 |
Correct |
103 ms |
220336 KB |
Output is correct |
4 |
Correct |
98 ms |
220344 KB |
Output is correct |
5 |
Correct |
99 ms |
220384 KB |
Output is correct |
6 |
Correct |
100 ms |
220408 KB |
Output is correct |
7 |
Correct |
102 ms |
220492 KB |
Output is correct |
8 |
Correct |
100 ms |
220316 KB |
Output is correct |
9 |
Correct |
103 ms |
220392 KB |
Output is correct |
10 |
Correct |
111 ms |
220512 KB |
Output is correct |
11 |
Correct |
101 ms |
220656 KB |
Output is correct |
12 |
Correct |
99 ms |
220468 KB |
Output is correct |
13 |
Correct |
99 ms |
220364 KB |
Output is correct |
14 |
Correct |
100 ms |
220696 KB |
Output is correct |
15 |
Correct |
101 ms |
220680 KB |
Output is correct |
16 |
Correct |
98 ms |
220604 KB |
Output is correct |
17 |
Correct |
110 ms |
221132 KB |
Output is correct |
18 |
Correct |
101 ms |
220644 KB |
Output is correct |
19 |
Correct |
108 ms |
220656 KB |
Output is correct |
20 |
Correct |
100 ms |
220492 KB |
Output is correct |
21 |
Correct |
101 ms |
220492 KB |
Output is correct |
22 |
Correct |
98 ms |
220668 KB |
Output is correct |
23 |
Correct |
100 ms |
220712 KB |
Output is correct |
24 |
Correct |
101 ms |
220948 KB |
Output is correct |
25 |
Correct |
99 ms |
220704 KB |
Output is correct |
26 |
Correct |
103 ms |
220748 KB |
Output is correct |
27 |
Correct |
99 ms |
220644 KB |
Output is correct |
28 |
Correct |
102 ms |
221496 KB |
Output is correct |
29 |
Correct |
108 ms |
223324 KB |
Output is correct |
30 |
Correct |
104 ms |
221232 KB |
Output is correct |
31 |
Correct |
102 ms |
221952 KB |
Output is correct |
32 |
Correct |
103 ms |
221548 KB |
Output is correct |
33 |
Correct |
118 ms |
226024 KB |
Output is correct |
34 |
Correct |
116 ms |
226060 KB |
Output is correct |
35 |
Correct |
121 ms |
225344 KB |
Output is correct |
36 |
Correct |
102 ms |
221176 KB |
Output is correct |
37 |
Correct |
125 ms |
228540 KB |
Output is correct |
38 |
Correct |
125 ms |
227880 KB |
Output is correct |
39 |
Correct |
122 ms |
227804 KB |
Output is correct |
40 |
Correct |
123 ms |
227804 KB |
Output is correct |
41 |
Correct |
123 ms |
227796 KB |
Output is correct |
42 |
Correct |
105 ms |
220816 KB |
Output is correct |
43 |
Correct |
103 ms |
220876 KB |
Output is correct |
44 |
Correct |
103 ms |
220612 KB |
Output is correct |
45 |
Correct |
227 ms |
243140 KB |
Output is correct |
46 |
Correct |
196 ms |
243264 KB |
Output is correct |
47 |
Correct |
184 ms |
255148 KB |
Output is correct |
48 |
Correct |
126 ms |
231440 KB |
Output is correct |
49 |
Correct |
119 ms |
227248 KB |
Output is correct |
50 |
Correct |
115 ms |
227192 KB |
Output is correct |
51 |
Correct |
147 ms |
235344 KB |
Output is correct |
52 |
Correct |
153 ms |
236728 KB |
Output is correct |
53 |
Correct |
115 ms |
224940 KB |
Output is correct |
54 |
Correct |
102 ms |
221752 KB |
Output is correct |
55 |
Correct |
106 ms |
223008 KB |
Output is correct |
56 |
Correct |
109 ms |
222796 KB |
Output is correct |
57 |
Correct |
146 ms |
240744 KB |
Output is correct |
58 |
Correct |
109 ms |
223652 KB |
Output is correct |
59 |
Correct |
112 ms |
225088 KB |
Output is correct |
60 |
Correct |
123 ms |
226792 KB |
Output is correct |
61 |
Correct |
129 ms |
225576 KB |
Output is correct |
62 |
Correct |
168 ms |
243988 KB |
Output is correct |
63 |
Runtime error |
176 ms |
262144 KB |
Execution killed with signal 9 |
64 |
Halted |
0 ms |
0 KB |
- |