#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
const int MAXN = 500100;
int h, w, k;
int getId (int i, int j) {
return i*w + j;
}
void construct_network(int H, int W, int K) {
h = H, w = W, k = K;
/// 0..H*W-1 - grid
vi istr1, istr2;
FOR(i, 0, h+w-2) {
int x, y;
if (i < w) {
x = 0;
y = w - i - 1;
} else {
y = 0;
x = i - w + 1;
}
vi ids;
while (x < h && y < w) {
ids.pb(getId(x, y));
x++; y++;
}
//cout << " istr i = " << i << ": ";
//for (int x : ids) cout << x << " ";
//cout << endl;
int id = add_or(ids);
//cout << " id = " << id << endl;
istr1.pb(id);
}
FOR(i, 0, h+w-2) {
int x, y;
if (i < h) {
x = i;
y = 0;
} else {
x = h-1;
y = i - x;
}
vi ids;
while (x >= 0 && y < w) {
ids.pb(getId(x, y));
x--; y++;
}
//cout << " istr i = " << i << ": ";
//for (int x : ids) cout << x << " ";
//cout << endl;
int id = add_or(ids);
//cout << " id = " << id << endl;
istr2.pb(id);
}
vi istrXOR1, istrXOR2;
FOR(i, 0, h+w-2) {
int x, y;
if (i < w) {
x = 0;
y = w - i - 1;
} else {
y = 0;
x = i - w + 1;
}
vi ids;
while (x < h && y < w) {
ids.pb(getId(x, y));
x++; y++;
}
//cout << " istr i = " << i << ": ";
//for (int x : ids) cout << x << " ";
//cout << endl;
int id = add_xor(ids);
//cout << " id = " << id << endl;
istrXOR1.pb(id);
}
FOR(i, 0, h+w-2) {
int x, y;
if (i < h) {
x = i;
y = 0;
} else {
x = h-1;
y = i - x;
}
vi ids;
while (x >= 0 && y < w) {
ids.pb(getId(x, y));
x--; y++;
}
//cout << " istr i = " << i << ": ";
//for (int x : ids) cout << x << " ";
//cout << endl;
int id = add_xor(ids);
//cout << " id = " << id << endl;
istrXOR2.pb(id);
}
vi istrPairs1, istrPairs2;
FOR(i, 0, (int)istr1.size()-k-1) {
vi toAnd = {istr1[i], istr1[i+k]};
int id = add_and(toAnd);
istrPairs1.pb(id);
}
int pairs1 = add_or(istrPairs1);
FOR(i, 0, (int)istr2.size()-k-1) {
vi toAnd = {istr2[i], istr2[i+k]};
int id = add_and(toAnd);
istrPairs2.pb(id);
}
int pairs2 = add_or(istrPairs2);
vi groups1;
FOR(i, 0, (int)istrXOR1.size()-1) {
vi ids;
FOR(j, max(0, i-k), min((int)istrXOR1.size()-1, i+k))
ids.pb(istrXOR1[j]);
int id = add_xor(ids);
id = add_not(id);
vi toAnd = {id, istrXOR1[i]};
id = add_and(toAnd);
groups1.pb(id);
}
vi groups2;
FOR(i, 0, (int)istrXOR2.size()-1) {
vi ids;
FOR(j, max(0, i-k), min((int)istrXOR2.size()-1, i+k))
ids.pb(istrXOR2[j]);
int id = add_xor(ids);
id = add_not(id);
vi toAnd = {id, istrXOR2[i]};
id = add_and(toAnd);
groups2.pb(id);
}
int gr1 = add_or(groups1);
int gr2 = add_or(groups2);
vi toAnd1 = {pairs1, gr2};
vi toAnd2 = {pairs2, gr1};
int id1 = add_and(toAnd1);
int id2 = add_and(toAnd2);
vi toOr = {id1, id2};
add_or(toOr);
}
/*
2 3 3
0 0 0 1
0 0 0 2
0 0 1 0
0 0 1 1
0 0 1 2
0 1 0 2
0 1 1 0
0 1 1 1
0 1 1 2
0 2 1 0
0 2 1 1
0 2 1 2
1 0 1 1
1 0 1 2
1 1 1 2
-1
out:
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
in:
2 3 1
0 0 0 1
0 0 0 2
0 0 1 0
0 0 1 1
0 0 1 2
0 1 0 2
0 1 1 0
0 1 1 1
0 1 1 2
0 2 1 0
0 2 1 1
0 2 1 2
1 0 1 1
1 0 1 2
1 1 1 2
-1
out:
2 3 1
0 2 1 0
-1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
8 ms |
972 KB |
Output is correct |
3 |
Correct |
8 ms |
992 KB |
Output is correct |
4 |
Correct |
10 ms |
972 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
7 ms |
844 KB |
Output is correct |
7 |
Correct |
10 ms |
972 KB |
Output is correct |
8 |
Correct |
11 ms |
992 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
6 ms |
716 KB |
Output is correct |
11 |
Correct |
9 ms |
972 KB |
Output is correct |
12 |
Correct |
13 ms |
888 KB |
Output is correct |
13 |
Correct |
12 ms |
1100 KB |
Output is correct |
14 |
Correct |
10 ms |
1056 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
6 ms |
716 KB |
Output is correct |
17 |
Correct |
13 ms |
972 KB |
Output is correct |
18 |
Correct |
13 ms |
984 KB |
Output is correct |
19 |
Correct |
13 ms |
1100 KB |
Output is correct |
20 |
Correct |
11 ms |
1072 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
292 KB |
on inputs (0, 0), (1, 1), expected 1, but computed 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2128 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
4 ms |
460 KB |
Output is correct |
4 |
Correct |
6 ms |
672 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
12 ms |
1228 KB |
Output is correct |
8 |
Correct |
14 ms |
1256 KB |
Output is correct |
9 |
Correct |
27 ms |
2248 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
on inputs (0, 1), (1, 0), expected 1, but computed 0 |
7 |
Halted |
0 ms |
0 KB |
- |