/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 30228;
int n, m;
int b[MAXN];
int p[MAXN];
vector<int> kek[MAXN];
queue<pair<pair<int, int>, int> > q;
bitset<30001> was[30001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> b[i] >> p[i];
}
for (int i = 0; i < m; i++) {
kek[b[i]].pb(p[i]);
}
if (b[1] == b[0]) {
cout << 0 << '\n';
return 0;
}
for (int i = 0; i < n; i++) {
sort(all(kek[i]));
kek[i].resize(distance(kek[i].begin(), unique(all(kek[i]))));
}
for (auto x: kek[b[0]]) {
q.push({{b[0], x}, 0});
was[b[0]][x] = true;
}
while (!q.empty()) {
auto x = q.front();
q.pop();
int pos = x.first.first;
int jump = x.first.second;
int cnt = x.second;
for (int f = pos - jump; f <= pos + jump; f += 2 * jump) {
if (f >= 0 && f < n) {
if (!was[f][jump]) {
was[f][jump] = true;
if (f == b[1]) {
cout << cnt + 1 << endl;
exit(0);
}
q.push({{f, jump}, cnt + 1});
}
for (auto y: kek[f]) {
if (!was[f][y]) {
was[f][y] = true;
q.push({{f, y}, cnt + 1});
}
}
kek[f].clear();
}
}
}
cout << -1 << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1020 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
10 ms |
1172 KB |
Output is correct |
10 |
Correct |
3 ms |
1272 KB |
Output is correct |
11 |
Correct |
3 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1400 KB |
Output is correct |
14 |
Correct |
3 ms |
1528 KB |
Output is correct |
15 |
Correct |
4 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
1016 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1276 KB |
Output is correct |
11 |
Correct |
4 ms |
1144 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
4 ms |
1528 KB |
Output is correct |
14 |
Correct |
4 ms |
1528 KB |
Output is correct |
15 |
Correct |
4 ms |
1528 KB |
Output is correct |
16 |
Correct |
3 ms |
1016 KB |
Output is correct |
17 |
Correct |
6 ms |
3064 KB |
Output is correct |
18 |
Correct |
3 ms |
1148 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
11 ms |
8440 KB |
Output is correct |
21 |
Correct |
3 ms |
1104 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
11 ms |
6520 KB |
Output is correct |
24 |
Correct |
12 ms |
7544 KB |
Output is correct |
25 |
Correct |
6 ms |
2552 KB |
Output is correct |
26 |
Correct |
12 ms |
7420 KB |
Output is correct |
27 |
Correct |
11 ms |
7632 KB |
Output is correct |
28 |
Correct |
13 ms |
8440 KB |
Output is correct |
29 |
Correct |
17 ms |
8440 KB |
Output is correct |
30 |
Correct |
12 ms |
8440 KB |
Output is correct |
31 |
Correct |
12 ms |
8440 KB |
Output is correct |
32 |
Correct |
12 ms |
8440 KB |
Output is correct |
33 |
Correct |
15 ms |
8440 KB |
Output is correct |
34 |
Correct |
13 ms |
8416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
1016 KB |
Output is correct |
5 |
Correct |
2 ms |
1096 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1020 KB |
Output is correct |
8 |
Correct |
3 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1276 KB |
Output is correct |
11 |
Correct |
3 ms |
1144 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
4 ms |
1528 KB |
Output is correct |
14 |
Correct |
4 ms |
1528 KB |
Output is correct |
15 |
Correct |
4 ms |
1528 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
5 ms |
3068 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
11 ms |
8568 KB |
Output is correct |
21 |
Correct |
3 ms |
1272 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
9 ms |
6392 KB |
Output is correct |
24 |
Correct |
11 ms |
7544 KB |
Output is correct |
25 |
Correct |
5 ms |
2460 KB |
Output is correct |
26 |
Correct |
11 ms |
7416 KB |
Output is correct |
27 |
Correct |
11 ms |
7672 KB |
Output is correct |
28 |
Correct |
12 ms |
8568 KB |
Output is correct |
29 |
Correct |
13 ms |
8440 KB |
Output is correct |
30 |
Correct |
11 ms |
8440 KB |
Output is correct |
31 |
Correct |
12 ms |
8440 KB |
Output is correct |
32 |
Correct |
12 ms |
8440 KB |
Output is correct |
33 |
Correct |
15 ms |
8440 KB |
Output is correct |
34 |
Correct |
13 ms |
8440 KB |
Output is correct |
35 |
Correct |
17 ms |
7160 KB |
Output is correct |
36 |
Correct |
5 ms |
1912 KB |
Output is correct |
37 |
Correct |
13 ms |
6392 KB |
Output is correct |
38 |
Correct |
15 ms |
5116 KB |
Output is correct |
39 |
Correct |
11 ms |
1784 KB |
Output is correct |
40 |
Correct |
11 ms |
2524 KB |
Output is correct |
41 |
Correct |
13 ms |
3576 KB |
Output is correct |
42 |
Correct |
16 ms |
8056 KB |
Output is correct |
43 |
Correct |
16 ms |
8284 KB |
Output is correct |
44 |
Correct |
17 ms |
9108 KB |
Output is correct |
45 |
Correct |
31 ms |
9348 KB |
Output is correct |
46 |
Correct |
24 ms |
9340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1016 KB |
Output is correct |
2 |
Correct |
2 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1016 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
3 ms |
1016 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1016 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1272 KB |
Output is correct |
11 |
Correct |
3 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1404 KB |
Output is correct |
13 |
Correct |
3 ms |
1400 KB |
Output is correct |
14 |
Correct |
4 ms |
1528 KB |
Output is correct |
15 |
Correct |
3 ms |
1528 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
5 ms |
3064 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
12 ms |
8568 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
3 ms |
1144 KB |
Output is correct |
23 |
Correct |
9 ms |
6392 KB |
Output is correct |
24 |
Correct |
11 ms |
7544 KB |
Output is correct |
25 |
Correct |
6 ms |
2556 KB |
Output is correct |
26 |
Correct |
12 ms |
7420 KB |
Output is correct |
27 |
Correct |
11 ms |
7672 KB |
Output is correct |
28 |
Correct |
12 ms |
8568 KB |
Output is correct |
29 |
Correct |
13 ms |
8440 KB |
Output is correct |
30 |
Correct |
11 ms |
8412 KB |
Output is correct |
31 |
Correct |
12 ms |
8444 KB |
Output is correct |
32 |
Correct |
12 ms |
8440 KB |
Output is correct |
33 |
Correct |
15 ms |
8440 KB |
Output is correct |
34 |
Correct |
13 ms |
8440 KB |
Output is correct |
35 |
Correct |
16 ms |
7160 KB |
Output is correct |
36 |
Correct |
5 ms |
2040 KB |
Output is correct |
37 |
Correct |
13 ms |
6392 KB |
Output is correct |
38 |
Correct |
14 ms |
4984 KB |
Output is correct |
39 |
Correct |
10 ms |
1784 KB |
Output is correct |
40 |
Correct |
11 ms |
2552 KB |
Output is correct |
41 |
Correct |
13 ms |
3576 KB |
Output is correct |
42 |
Correct |
16 ms |
8056 KB |
Output is correct |
43 |
Correct |
16 ms |
8312 KB |
Output is correct |
44 |
Correct |
17 ms |
9080 KB |
Output is correct |
45 |
Correct |
32 ms |
9464 KB |
Output is correct |
46 |
Correct |
24 ms |
9340 KB |
Output is correct |
47 |
Correct |
28 ms |
13688 KB |
Output is correct |
48 |
Correct |
10 ms |
1916 KB |
Output is correct |
49 |
Correct |
10 ms |
1916 KB |
Output is correct |
50 |
Correct |
8 ms |
1784 KB |
Output is correct |
51 |
Correct |
104 ms |
77052 KB |
Output is correct |
52 |
Correct |
120 ms |
89820 KB |
Output is correct |
53 |
Correct |
33 ms |
19064 KB |
Output is correct |
54 |
Correct |
71 ms |
61304 KB |
Output is correct |
55 |
Correct |
94 ms |
77944 KB |
Output is correct |
56 |
Correct |
139 ms |
112632 KB |
Output is correct |
57 |
Correct |
5 ms |
2680 KB |
Output is correct |
58 |
Correct |
139 ms |
111872 KB |
Output is correct |
59 |
Correct |
131 ms |
104136 KB |
Output is correct |
60 |
Correct |
130 ms |
104184 KB |
Output is correct |
61 |
Correct |
126 ms |
99036 KB |
Output is correct |
62 |
Correct |
215 ms |
112632 KB |
Output is correct |
63 |
Correct |
251 ms |
112120 KB |
Output is correct |
64 |
Correct |
268 ms |
112120 KB |
Output is correct |
65 |
Correct |
351 ms |
112348 KB |
Output is correct |
66 |
Correct |
461 ms |
112248 KB |
Output is correct |
67 |
Correct |
296 ms |
112244 KB |
Output is correct |