This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |