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;
using vi = vector<int>;
int No() {
return add_xor({0,0});
}
int Yes() {
return add_not(add_xor({0,0}));
}
int solve(int H, int W, int K) {
auto get1 = [&](int x) {
int i, j;
vi res;
for (i=0, j=x; i<H; ++i, --j) {
if (0 <= j && j < W) {
res.push_back(i*W+j);
}
}
return res;
};
auto get2 = [&](int x) {
int i, j;
vi res;
for (i=0, j=W-1-x; i<H; ++i, ++j) {
if (0 <= j && j < W) {
res.push_back(i*W+j);
}
}
return res;
};
vi candidate_conditions;
for (int k = 0; k < H+W; ++k) {
vi A = get1(k), B = get1(k+K);
if (empty(A) || empty(B)) continue;
int a = add_xor(A), b = add_xor(B);
candidate_conditions.push_back(add_and({a,b}));
}
for (int k = 0; k < H+W; ++k) {
vi A = get2(k), B = get2(k+K);
if (empty(A) || empty(B)) continue;
int a = add_xor(A), b = add_xor(B);
candidate_conditions.push_back(add_and({a,b}));
}
if (empty(candidate_conditions)) return No();
return add_or(candidate_conditions);
}
void construct_network(int H, int W, int K) {
auto hor_box = [&] {
vi res;
vi P(H), Q(H);
for (int i=0; i<H; ++i) {
vi box;
for (int j=0; j<W; ++j) box.push_back(i*W+j);
P[i] = add_or(box);
Q[i] = add_xor(box);
}
for (int i=1; i<H; ++i) {
P[i] = add_or({P[i-1], P[i]});
Q[i] = add_xor({Q[i-1], Q[i]});
}
for (int k=0; k+K<H; ++k) {
vi box;
int x = P[k+K];
if (k) x = add_xor({x,P[k-1]});
int y = Q[k+K];
if (k) y = add_xor({y,Q[k-1]});
res.push_back( add_and({ x, add_not(y) }) );
}
if (empty(res)) return Yes();
return add_or(res);
};
auto ver_box = [&] {
vi res;
vi P(W), Q(W);
for (int i=0; i<W; ++i) {
vi box;
for (int j=0; j<H; ++j) box.push_back(j*W+i);
P[i] = add_or(box);
Q[i] = add_xor(box);
}
for (int i=1; i<W; ++i) {
P[i] = add_or({P[i-1], P[i]});
Q[i] = add_xor({Q[i-1], Q[i]});
}
for (int k=0; k+K<W; ++k) {
vi box;
int x = P[k+K];
if (k) x = add_xor({x,P[k-1]});
int y = Q[k+K];
if (k) y = add_xor({y,Q[k-1]});
res.push_back( add_and({ x, add_not(y) }) );
}
if (empty(res)) return Yes();
return add_or(res);
};
int condition1 = add_and({ ver_box(), hor_box() });
int condition2 = solve(H,W,K);
add_and({condition1,condition2});
}
# | 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... |