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 <vector>
#include "vision.h"
#include <iostream>
using namespace std;
struct picture
{
int H, W;
int dignr;
int getnr(int y, int x)
{
return y*W + x;
}
int inside(int y, int x)
{
return (y >= 0) && (x >= 0) && (x < W) && (y < H);
}
vector<int> leftdig;
vector<int> leftdig_double;
vector<int> rightdig;
vector<int> rightdig_double;
void init_dig()
{
for (int i = 0; i < dignr; i++)
{
vector<int> fields;
for (int j = 0; j < H; j++)
{
int x = i - j;
int y = j;
if (!inside(y, x)) continue;
fields.push_back(getnr(y, x));
}
int n_in = add_or(fields);
leftdig.push_back(n_in);
int xr = add_xor(fields);
leftdig_double.push_back(add_xor({n_in, xr}));
}
for (int i = W - dignr; i < W; i++)
{
vector<int> fields;
for (int j = 0; j < H; j++)
{
int x = i + j;
int y = j;
if (!inside(y, x)) continue;
fields.push_back(getnr(y, x));
}
int n_in = add_or(fields);
rightdig.push_back(n_in);
int xr = add_xor(fields);
rightdig_double.push_back(add_xor({n_in, xr}));
}
}
void init(int iH, int iW)
{
H = iH;
W = iW;
dignr = H + W - 1;
}
int smaller(int k)
{
vector<int> allleftd;
for (int i = 0; i < dignr; i++)
{
vector<int> ld;
for (int j = 0; j <= k; j++)
{
if (i + j >= dignr) continue;
ld.push_back(leftdig[i + j]);
ld.push_back(leftdig_double[i + j]);
}
int n_or = add_or(ld);
int n_xr = add_xor(ld);
allleftd.push_back(add_xor({n_or, n_xr}));
}
int l_in = add_or(allleftd);
vector<int> allrightd;
for (int i = 0; i < dignr; i++)
{
vector<int> ld;
for (int j = 0; j <= k; j++)
{
if (i + j >= dignr) continue;
ld.push_back(rightdig[i + j]);
ld.push_back(rightdig_double[i + j]);
}
int n_or = add_or(ld);
int n_xr = add_xor(ld);
allrightd.push_back(add_xor({n_or, n_xr}));
}
int r_in = add_or(allrightd);
return add_and({r_in, l_in});
}
};
void construct_network(int H, int W, int K)
{
picture pic;
pic.init(H, W);
pic.init_dig();
add_xor({pic.smaller(K), pic.smaller(K - 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... |