///
/// ♪ Pizza mozzarella rella rella rella... ♪
///
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = (l); x < (r); ++x)
#define LoopR(x, l, r) for(int x = (r)-1; x >= (l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
typedef std::pair<ll ,ll > pll;
using namespace std;
const int N = 30'010;
const int mod = 6000023;
struct mymap
{
vector<pii> v[mod];
int count(int x)
{
int y = x%mod;
for(auto& [a, b] : v[y])
if(a==x)
return 1;
return 0;
}
int& operator[](int x)
{
int y = x%mod;
for(auto& [a, b] : v[y])
if(a==x)
return b;
v[y].emplace_back(x,0);
return v[y].back().S;
}
};
mymap d;
vector<int> P[N];
bool vis[N];
int n, m;
void bfs(int sv, int sp)
{
vector<int> q;
vis[sv] = 1;
for(auto p : P[sv]) if(!d.count(sv<<15^p)) d[sv<<15^p] = 0, q.push_back(sv<<15^p);
if(!d.count(sv<<15^sp)) d[sv<<15^sp] = 0, q.push_back(sv<<15^sp);
for(int i = 0, j = q.size(), d = 0; i < q.size(); j = q.size(), ++d) for(; i < j; ++i)
{
if(q.size() > 8'000'000) exit(0);
int v = q[i]>>15, p = q[i]&32767;
//cerr << v << ' ' << p << ": " << d << '\n';
int u = v+p;
if(0 <= u && u < n)
{
if(!vis[u]){
vis[u] = 1;
for(auto p : P[u]) if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
}
if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
}
u = v-p;
if(0 <= u && u < n)
{
if(!vis[u]){
vis[u] = 1;
for(auto p : P[u]) if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
}
if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
}
}
}
bool isPrime(int n)
{
for(int d = 2; d*d <= n; ++d)
if(n%d == 0)
return 0;
return 1;
}
int main()
{
//Loop(i,6000012,INT_MAX) if(isPrime(i)){cout << i;break;}
FAST;
cin >> n >> m;
int p, src, des, dmy;
cin >> src >> p;
cin >> des >> dmy;
P[des].push_back(dmy);
Loop(i,2,m)
{
int v, p;
cin >> v >> p;
P[v].push_back(p);
}
bfs(src, p);
cout << (d.count(des<<15^dmy)? d[des<<15^dmy]: -1) << '\n';
}
Compilation message
skyscraper.cpp: In function 'void bfs(int, int)':
skyscraper.cpp:57:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0, j = q.size(), d = 0; i < q.size(); j = q.size(), ++d) for(; i < j; ++i)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
141852 KB |
Output is correct |
2 |
Correct |
74 ms |
141816 KB |
Output is correct |
3 |
Correct |
74 ms |
141780 KB |
Output is correct |
4 |
Correct |
76 ms |
141896 KB |
Output is correct |
5 |
Correct |
75 ms |
141800 KB |
Output is correct |
6 |
Correct |
77 ms |
141988 KB |
Output is correct |
7 |
Correct |
79 ms |
141808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
141860 KB |
Output is correct |
2 |
Correct |
76 ms |
141896 KB |
Output is correct |
3 |
Correct |
74 ms |
142020 KB |
Output is correct |
4 |
Correct |
76 ms |
141780 KB |
Output is correct |
5 |
Correct |
77 ms |
141900 KB |
Output is correct |
6 |
Correct |
75 ms |
141892 KB |
Output is correct |
7 |
Correct |
74 ms |
141896 KB |
Output is correct |
8 |
Correct |
73 ms |
141904 KB |
Output is correct |
9 |
Correct |
74 ms |
141860 KB |
Output is correct |
10 |
Correct |
76 ms |
141960 KB |
Output is correct |
11 |
Correct |
77 ms |
142008 KB |
Output is correct |
12 |
Correct |
78 ms |
141876 KB |
Output is correct |
13 |
Correct |
78 ms |
141872 KB |
Output is correct |
14 |
Correct |
76 ms |
142104 KB |
Output is correct |
15 |
Correct |
82 ms |
142020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
141824 KB |
Output is correct |
2 |
Correct |
76 ms |
141888 KB |
Output is correct |
3 |
Correct |
74 ms |
141892 KB |
Output is correct |
4 |
Correct |
80 ms |
141824 KB |
Output is correct |
5 |
Correct |
76 ms |
141896 KB |
Output is correct |
6 |
Correct |
74 ms |
141808 KB |
Output is correct |
7 |
Correct |
75 ms |
141984 KB |
Output is correct |
8 |
Correct |
77 ms |
141848 KB |
Output is correct |
9 |
Correct |
77 ms |
141896 KB |
Output is correct |
10 |
Correct |
78 ms |
141904 KB |
Output is correct |
11 |
Correct |
79 ms |
142064 KB |
Output is correct |
12 |
Correct |
78 ms |
141876 KB |
Output is correct |
13 |
Correct |
77 ms |
141892 KB |
Output is correct |
14 |
Correct |
77 ms |
142064 KB |
Output is correct |
15 |
Correct |
77 ms |
142088 KB |
Output is correct |
16 |
Correct |
90 ms |
141824 KB |
Output is correct |
17 |
Correct |
80 ms |
142392 KB |
Output is correct |
18 |
Correct |
77 ms |
141968 KB |
Output is correct |
19 |
Correct |
75 ms |
141876 KB |
Output is correct |
20 |
Correct |
77 ms |
141948 KB |
Output is correct |
21 |
Correct |
78 ms |
141800 KB |
Output is correct |
22 |
Correct |
78 ms |
141828 KB |
Output is correct |
23 |
Correct |
78 ms |
142148 KB |
Output is correct |
24 |
Correct |
80 ms |
142356 KB |
Output is correct |
25 |
Correct |
80 ms |
142284 KB |
Output is correct |
26 |
Correct |
88 ms |
142144 KB |
Output is correct |
27 |
Correct |
78 ms |
142068 KB |
Output is correct |
28 |
Correct |
86 ms |
142728 KB |
Output is correct |
29 |
Correct |
96 ms |
144052 KB |
Output is correct |
30 |
Correct |
88 ms |
142604 KB |
Output is correct |
31 |
Correct |
82 ms |
143156 KB |
Output is correct |
32 |
Correct |
81 ms |
142660 KB |
Output is correct |
33 |
Correct |
104 ms |
146128 KB |
Output is correct |
34 |
Correct |
105 ms |
146164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
141892 KB |
Output is correct |
2 |
Correct |
76 ms |
141816 KB |
Output is correct |
3 |
Correct |
87 ms |
141860 KB |
Output is correct |
4 |
Correct |
75 ms |
141784 KB |
Output is correct |
5 |
Correct |
76 ms |
141900 KB |
Output is correct |
6 |
Correct |
83 ms |
141928 KB |
Output is correct |
7 |
Correct |
75 ms |
141892 KB |
Output is correct |
8 |
Correct |
76 ms |
141860 KB |
Output is correct |
9 |
Correct |
75 ms |
141816 KB |
Output is correct |
10 |
Correct |
74 ms |
141960 KB |
Output is correct |
11 |
Correct |
88 ms |
142020 KB |
Output is correct |
12 |
Correct |
81 ms |
141880 KB |
Output is correct |
13 |
Correct |
78 ms |
141884 KB |
Output is correct |
14 |
Correct |
75 ms |
142024 KB |
Output is correct |
15 |
Correct |
76 ms |
142084 KB |
Output is correct |
16 |
Correct |
75 ms |
141804 KB |
Output is correct |
17 |
Correct |
80 ms |
142456 KB |
Output is correct |
18 |
Correct |
85 ms |
141892 KB |
Output is correct |
19 |
Correct |
75 ms |
141916 KB |
Output is correct |
20 |
Correct |
77 ms |
142012 KB |
Output is correct |
21 |
Correct |
76 ms |
141892 KB |
Output is correct |
22 |
Correct |
79 ms |
141808 KB |
Output is correct |
23 |
Correct |
78 ms |
142120 KB |
Output is correct |
24 |
Correct |
81 ms |
142440 KB |
Output is correct |
25 |
Correct |
78 ms |
142088 KB |
Output is correct |
26 |
Correct |
77 ms |
142152 KB |
Output is correct |
27 |
Correct |
87 ms |
142148 KB |
Output is correct |
28 |
Correct |
84 ms |
142732 KB |
Output is correct |
29 |
Correct |
91 ms |
143968 KB |
Output is correct |
30 |
Correct |
80 ms |
142532 KB |
Output is correct |
31 |
Correct |
83 ms |
143212 KB |
Output is correct |
32 |
Correct |
83 ms |
142704 KB |
Output is correct |
33 |
Correct |
105 ms |
146108 KB |
Output is correct |
34 |
Correct |
107 ms |
146088 KB |
Output is correct |
35 |
Correct |
119 ms |
145632 KB |
Output is correct |
36 |
Correct |
82 ms |
142544 KB |
Output is correct |
37 |
Correct |
129 ms |
148220 KB |
Output is correct |
38 |
Correct |
129 ms |
147700 KB |
Output is correct |
39 |
Correct |
130 ms |
147680 KB |
Output is correct |
40 |
Correct |
129 ms |
147744 KB |
Output is correct |
41 |
Correct |
127 ms |
147676 KB |
Output is correct |
42 |
Correct |
83 ms |
142284 KB |
Output is correct |
43 |
Correct |
85 ms |
142160 KB |
Output is correct |
44 |
Correct |
82 ms |
142248 KB |
Output is correct |
45 |
Correct |
227 ms |
159028 KB |
Output is correct |
46 |
Correct |
203 ms |
158940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
141824 KB |
Output is correct |
2 |
Correct |
76 ms |
141880 KB |
Output is correct |
3 |
Correct |
83 ms |
141868 KB |
Output is correct |
4 |
Correct |
76 ms |
141832 KB |
Output is correct |
5 |
Correct |
79 ms |
141904 KB |
Output is correct |
6 |
Correct |
77 ms |
141832 KB |
Output is correct |
7 |
Correct |
77 ms |
141856 KB |
Output is correct |
8 |
Correct |
75 ms |
141828 KB |
Output is correct |
9 |
Correct |
74 ms |
141796 KB |
Output is correct |
10 |
Correct |
76 ms |
141864 KB |
Output is correct |
11 |
Correct |
77 ms |
142136 KB |
Output is correct |
12 |
Correct |
75 ms |
141824 KB |
Output is correct |
13 |
Correct |
75 ms |
141920 KB |
Output is correct |
14 |
Correct |
80 ms |
142104 KB |
Output is correct |
15 |
Correct |
77 ms |
142020 KB |
Output is correct |
16 |
Correct |
74 ms |
141912 KB |
Output is correct |
17 |
Correct |
81 ms |
142436 KB |
Output is correct |
18 |
Correct |
75 ms |
141864 KB |
Output is correct |
19 |
Correct |
78 ms |
141800 KB |
Output is correct |
20 |
Correct |
101 ms |
142004 KB |
Output is correct |
21 |
Correct |
78 ms |
141856 KB |
Output is correct |
22 |
Correct |
77 ms |
141892 KB |
Output is correct |
23 |
Correct |
85 ms |
142156 KB |
Output is correct |
24 |
Correct |
83 ms |
142296 KB |
Output is correct |
25 |
Correct |
81 ms |
142220 KB |
Output is correct |
26 |
Correct |
78 ms |
142084 KB |
Output is correct |
27 |
Correct |
80 ms |
142044 KB |
Output is correct |
28 |
Correct |
81 ms |
142704 KB |
Output is correct |
29 |
Correct |
91 ms |
144016 KB |
Output is correct |
30 |
Correct |
82 ms |
142540 KB |
Output is correct |
31 |
Correct |
85 ms |
143172 KB |
Output is correct |
32 |
Correct |
81 ms |
142672 KB |
Output is correct |
33 |
Correct |
114 ms |
146280 KB |
Output is correct |
34 |
Correct |
111 ms |
146108 KB |
Output is correct |
35 |
Correct |
113 ms |
145640 KB |
Output is correct |
36 |
Correct |
85 ms |
142588 KB |
Output is correct |
37 |
Correct |
150 ms |
148024 KB |
Output is correct |
38 |
Correct |
128 ms |
147684 KB |
Output is correct |
39 |
Correct |
133 ms |
147756 KB |
Output is correct |
40 |
Correct |
140 ms |
147772 KB |
Output is correct |
41 |
Correct |
127 ms |
147708 KB |
Output is correct |
42 |
Correct |
84 ms |
142296 KB |
Output is correct |
43 |
Correct |
81 ms |
142148 KB |
Output is correct |
44 |
Correct |
81 ms |
142156 KB |
Output is correct |
45 |
Correct |
202 ms |
159044 KB |
Output is correct |
46 |
Correct |
210 ms |
159024 KB |
Output is correct |
47 |
Correct |
337 ms |
167364 KB |
Output is correct |
48 |
Correct |
85 ms |
142276 KB |
Output is correct |
49 |
Correct |
84 ms |
142332 KB |
Output is correct |
50 |
Correct |
79 ms |
142172 KB |
Output is correct |
51 |
Correct |
189 ms |
153400 KB |
Output is correct |
52 |
Correct |
207 ms |
154472 KB |
Output is correct |
53 |
Correct |
130 ms |
145596 KB |
Output is correct |
54 |
Correct |
82 ms |
142408 KB |
Output is correct |
55 |
Correct |
83 ms |
142828 KB |
Output is correct |
56 |
Correct |
98 ms |
143832 KB |
Output is correct |
57 |
Correct |
219 ms |
157324 KB |
Output is correct |
58 |
Correct |
98 ms |
144524 KB |
Output is correct |
59 |
Correct |
108 ms |
145340 KB |
Output is correct |
60 |
Correct |
117 ms |
146344 KB |
Output is correct |
61 |
Correct |
108 ms |
145788 KB |
Output is correct |
62 |
Correct |
227 ms |
159800 KB |
Output is correct |
63 |
Correct |
872 ms |
217660 KB |
Output is correct |
64 |
Execution timed out |
1049 ms |
232936 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |