# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221344 | galca | Vision Program (IOI19_vision) | C++14 | 0 ms | 0 KiB |
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 <vector>
using namespace std;
void construct_network(int H, int W, int K) {
vector<int> positions;
vector<int> positions2;
vector<int> positions3;
positions2.push_back(0);
positions2.push_back(0);
positions3.push_back(0);
positions3.push_back(0);
positions3.push_back(0);
for (int i = 0; i < W; i++) {
positions.push_back(i);
}
for (int j = 0; j < H; j++) {
add_xor(positions);
for (int i = 0; i < W; i++) {
positions[i] += W;
}
}
positions.erase(positions.begin(), positions.end());
for (int i = 0; i < H; i++) {
positions.push_back(i*W);
}
for (int j = 0; j < W; j++) {
add_xor(positions);
for (int i = 0; i < H; i++) {
positions[i] += 1;
}
}
vector<int> positions_final_or;
// starting from W*H + H + W, put xor of all positions
positions.erase(positions.begin(), positions.end());
// last one is always 0
// indeces from H*W+H+W to H*W+H+W+H
for (int i = 0; i < H; i++) {
positions.push_back(W*H + i);
add_xor(positions);
}
positions.erase(positions.begin(), positions.end());
for (int i = 0; i < W; i++) {
positions.push_back(W*H + H + i);
add_xor(positions);
}
// we now have H+W bits, which we need to sum and compare to K
// H+W < 400 => 9 bits are enough for the sum
int pos = H*W + H + W;
// lets create 0 and 1 first
int zero_pos = W*H + H + W + H - 1
int one_pos = add_not(zero_pos);
int tmp = H + W - 2;
int num_bits = 0;
while (tmp > 0) {
++num_bits;
tmp >>= 1;
}
vector<int> counter;
// set initial counter to 0
for (int i = 0; i < num_bits; i++) {
counter.push_back(zero_pos);
}
for (int i = 0; i < H + W; i++) {
int carry_pos = pos + i;
//int new_bit = pos + i;
// adding next elements
for (int j = 0; j < num_bits; j++) {
positions2[0] = counter[j];
positions2[1] = carry_pos;
int new_res = add_xor(positions2);
positions2[0] = counter[j];
positions2[1] = carry_pos;
carry_pos = add_and(positions2);
counter[j] = new_res;
}
}
// compare counter to K
vector<int> final_and;
for (int j = 0; j < num_bits; j++) {
positions2[0] = (K & 1) ? one_pos : zero_pos;
positions2[1] = counter[j];
final_and.push_back(add_xor(positions2));
K >>= 1;
}
add_not(add_or(final_and));
}