#include "vision.h"
#include <bits/stdc++.h>
struct Diag {
std::vector <std::pair <int, int>> a;
Diag(const std::set <std::pair <int, int>>& st) {
for (const auto& p : st) {
a.emplace_back(p);
}
}
int ind_or;
int ind_xor;
int ind_not_xor;
int ind_has_two;
};
constexpr bool ok(int i, int j, int n, int m) {
return i >= 0 && j >= 0 && i < n && j < m;
}
std::vector <int> conv(int m, const std::vector <std::pair <int, int>>& a) {
std::vector <int> res(a.size());
for (int i = 0; i < (int) a.size(); i++) {
res[i] = a[i].first * m + a[i].second;
}
return res;
}
void construct_network(int n, int m, int k) {
std::vector <Diag> up, down;
{
std::set <std::pair <int, int>> st;
st.insert({ 0, 0 });
while (st.size()) {
down.push_back(Diag(st));
std::set <std::pair <int, int>> stt;
for (auto p : st) {
if (ok(p.first + 1, p.second, n, m)) stt.insert({ p.first + 1, p.second });
if (ok(p.first, p.second + 1, n, m)) stt.insert({ p.first, p.second + 1 });
}
st = stt;
}
}
{
std::set <std::pair <int, int>> st;
st.insert({ n - 1, 0 });
while (st.size()) {
up.push_back(Diag(st));
std::set <std::pair <int, int>> stt;
for (auto p : st) {
if (ok(p.first - 1, p.second, n, m)) stt.insert({ p.first - 1, p.second });
if (ok(p.first, p.second + 1, n, m)) stt.insert({ p.first, p.second + 1 });
}
st = stt;
}
}
for (Diag& d : down) {
d.ind_or = add_or(conv(m, d.a));
d.ind_xor = add_xor(conv(m, d.a));
d.ind_not_xor = add_not(d.ind_xor);
d.ind_has_two = add_and({ d.ind_or, d.ind_not_xor });
}
for (Diag& d : up) {
d.ind_or = add_or(conv(m, d.a));
d.ind_xor = add_xor(conv(m, d.a));
d.ind_not_xor = add_not(d.ind_xor);
d.ind_has_two = add_and({ d.ind_or, d.ind_not_xor });
}
//{ not xor { or } } and { or }
//or
//or { d.ind_has_two }
auto go = [] (const std::vector <Diag>& diag, int kk) -> int {
std::vector <int> inds;
std::vector <Diag> cur;
for (const Diag& d : diag) {
cur.push_back(d);
if ((int) cur.size() > kk) {
cur.erase(cur.begin());
}
assert((int) cur.size() <= kk);
if ((int) cur.size() == kk) {
std::vector <int> idx;
for (const Diag& dd : cur) {
idx.push_back(dd.ind_or);
}
int ind_or = add_or(idx);
int ind_xor = add_xor(idx);
int ind_not_xor = add_not(ind_xor);
int ind_and = add_and({ ind_not_xor, ind_or });
idx.clear();
for (const Diag& dd : cur) {
idx.push_back(dd.ind_has_two);
}
int ind_h2_or = add_or(idx);
inds.push_back(add_or({ ind_and, ind_h2_or }));
}
}
return add_or(inds);
};
int ind_kp1_up = go(up, k + 1);
int ind_kp1_down = go(down, k + 1);
int ind_kp0_up = go(up, k);
int ind_kp0_down = go(down, k);
int ind_kp1_both = add_and({ ind_kp1_up, ind_kp1_down });
int ind_kp0_both = add_and({ ind_kp0_up, ind_kp0_down });
int ind_kp0_not = add_not(ind_kp0_both);
add_and({ ind_kp1_both, ind_kp0_not });
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
2 ms |
424 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
296 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
2 ms |
424 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
296 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
17 ms |
2200 KB |
Output is correct |
39 |
Correct |
4 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
568 KB |
Output is correct |
41 |
Correct |
5 ms |
976 KB |
Output is correct |
42 |
Correct |
5 ms |
724 KB |
Output is correct |
43 |
Correct |
10 ms |
1360 KB |
Output is correct |
44 |
Correct |
17 ms |
2160 KB |
Output is correct |
45 |
Correct |
27 ms |
2380 KB |
Output is correct |
46 |
Correct |
18 ms |
2056 KB |
Output is correct |
47 |
Correct |
8 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
724 KB |
Output is correct |
2 |
Correct |
14 ms |
1620 KB |
Output is correct |
3 |
Correct |
15 ms |
1512 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
5 ms |
812 KB |
Output is correct |
6 |
Correct |
13 ms |
1488 KB |
Output is correct |
7 |
Correct |
14 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
772 KB |
Output is correct |
10 |
Correct |
11 ms |
1360 KB |
Output is correct |
11 |
Correct |
13 ms |
1552 KB |
Output is correct |
12 |
Correct |
16 ms |
1580 KB |
Output is correct |
13 |
Correct |
10 ms |
1236 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
11 ms |
1488 KB |
Output is correct |
17 |
Correct |
13 ms |
1624 KB |
Output is correct |
18 |
Correct |
14 ms |
1620 KB |
Output is correct |
19 |
Correct |
11 ms |
1308 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
5 ms |
724 KB |
Output is correct |
4 |
Correct |
7 ms |
980 KB |
Output is correct |
5 |
Correct |
10 ms |
1108 KB |
Output is correct |
6 |
Correct |
7 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
552 KB |
Output is correct |
8 |
Correct |
10 ms |
1040 KB |
Output is correct |
9 |
Correct |
13 ms |
1620 KB |
Output is correct |
10 |
Correct |
18 ms |
1760 KB |
Output is correct |
11 |
Correct |
13 ms |
1492 KB |
Output is correct |
12 |
Correct |
7 ms |
812 KB |
Output is correct |
13 |
Correct |
4 ms |
724 KB |
Output is correct |
14 |
Correct |
15 ms |
1488 KB |
Output is correct |
15 |
Correct |
13 ms |
1388 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
724 KB |
Output is correct |
18 |
Correct |
14 ms |
1556 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
19 ms |
2260 KB |
Output is correct |
21 |
Correct |
45 ms |
4408 KB |
Output is correct |
22 |
Correct |
50 ms |
4276 KB |
Output is correct |
23 |
Correct |
17 ms |
1876 KB |
Output is correct |
24 |
Correct |
19 ms |
2204 KB |
Output is correct |
25 |
Correct |
45 ms |
4620 KB |
Output is correct |
26 |
Correct |
16 ms |
1924 KB |
Output is correct |
27 |
Incorrect |
15 ms |
2640 KB |
WA in grader: Too many instructions |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
2644 KB |
WA in grader: Too many instructions |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
2 ms |
424 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
296 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
17 ms |
2200 KB |
Output is correct |
39 |
Correct |
4 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
568 KB |
Output is correct |
41 |
Correct |
5 ms |
976 KB |
Output is correct |
42 |
Correct |
5 ms |
724 KB |
Output is correct |
43 |
Correct |
10 ms |
1360 KB |
Output is correct |
44 |
Correct |
17 ms |
2160 KB |
Output is correct |
45 |
Correct |
27 ms |
2380 KB |
Output is correct |
46 |
Correct |
18 ms |
2056 KB |
Output is correct |
47 |
Correct |
8 ms |
1092 KB |
Output is correct |
48 |
Correct |
4 ms |
724 KB |
Output is correct |
49 |
Correct |
14 ms |
1620 KB |
Output is correct |
50 |
Correct |
15 ms |
1512 KB |
Output is correct |
51 |
Correct |
2 ms |
428 KB |
Output is correct |
52 |
Correct |
5 ms |
812 KB |
Output is correct |
53 |
Correct |
13 ms |
1488 KB |
Output is correct |
54 |
Correct |
14 ms |
1364 KB |
Output is correct |
55 |
Correct |
2 ms |
468 KB |
Output is correct |
56 |
Correct |
3 ms |
772 KB |
Output is correct |
57 |
Correct |
11 ms |
1360 KB |
Output is correct |
58 |
Correct |
13 ms |
1552 KB |
Output is correct |
59 |
Correct |
16 ms |
1580 KB |
Output is correct |
60 |
Correct |
10 ms |
1236 KB |
Output is correct |
61 |
Correct |
2 ms |
468 KB |
Output is correct |
62 |
Correct |
3 ms |
724 KB |
Output is correct |
63 |
Correct |
11 ms |
1488 KB |
Output is correct |
64 |
Correct |
13 ms |
1624 KB |
Output is correct |
65 |
Correct |
14 ms |
1620 KB |
Output is correct |
66 |
Correct |
11 ms |
1308 KB |
Output is correct |
67 |
Correct |
2 ms |
424 KB |
Output is correct |
68 |
Correct |
1 ms |
212 KB |
Output is correct |
69 |
Correct |
1 ms |
304 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
296 KB |
Output is correct |
72 |
Correct |
5 ms |
724 KB |
Output is correct |
73 |
Correct |
7 ms |
980 KB |
Output is correct |
74 |
Correct |
10 ms |
1108 KB |
Output is correct |
75 |
Correct |
7 ms |
852 KB |
Output is correct |
76 |
Correct |
3 ms |
552 KB |
Output is correct |
77 |
Correct |
10 ms |
1040 KB |
Output is correct |
78 |
Correct |
13 ms |
1620 KB |
Output is correct |
79 |
Correct |
18 ms |
1760 KB |
Output is correct |
80 |
Correct |
13 ms |
1492 KB |
Output is correct |
81 |
Correct |
7 ms |
812 KB |
Output is correct |
82 |
Correct |
4 ms |
724 KB |
Output is correct |
83 |
Correct |
15 ms |
1488 KB |
Output is correct |
84 |
Correct |
13 ms |
1388 KB |
Output is correct |
85 |
Correct |
2 ms |
468 KB |
Output is correct |
86 |
Correct |
5 ms |
724 KB |
Output is correct |
87 |
Correct |
14 ms |
1556 KB |
Output is correct |
88 |
Correct |
2 ms |
468 KB |
Output is correct |
89 |
Correct |
19 ms |
2260 KB |
Output is correct |
90 |
Correct |
45 ms |
4408 KB |
Output is correct |
91 |
Correct |
50 ms |
4276 KB |
Output is correct |
92 |
Correct |
17 ms |
1876 KB |
Output is correct |
93 |
Correct |
19 ms |
2204 KB |
Output is correct |
94 |
Correct |
45 ms |
4620 KB |
Output is correct |
95 |
Correct |
16 ms |
1924 KB |
Output is correct |
96 |
Incorrect |
15 ms |
2640 KB |
WA in grader: Too many instructions |
97 |
Halted |
0 ms |
0 KB |
- |