# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221303 | 2020-04-09T20:46:00 Z | galca | Vision Program (IOI19_vision) | C++14 | 0 ms | 0 KB |
#include <vision.h> #include <vector> using namespace std; void construct_network(int H, int W, int K) { vector<int> positions; vector<int> positions2; positions2.push_back(0); positions2.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 + 2 * H + 2 * W; // lets create 0 and 1 first int zero_pos = W*H + H + W + H - 1; positions.erase(positions.begin(), positions.end()); positions.push_back(zero_pos); int one_pos = add_not(positions); int num_bits = 10; // set initial counter to 0 for (int i = 0; i < 3*num_bits; i++) { add_or(positions); } int counter_pos = one_pos + 1; for (int i = 0; i < H + W; i++) { int carry_pos = zero_pos; // adding next elements for (int j = 0; j < num_bits; j++) { vector<int> res(3); res[0] = counter_pos + j * 3; res[1] = pos + i; res[2] = carry_pos; add_xor(res); vector<int> carry(2); carry[0] = counter_pos + j * 3; carry[1] = pos + i; carry[0] = add_and(carry); carry[1] = carry_pos; carry_pos = add_or(carry); } counter_pos = counter_pos + num_bits * 3; } // compare counter to K vector<int> final_and; vector<int> bits(2); for (int j = 0; j < num_bits; j++) { bits[0] = (K & 1) ? one_pos : zero_pos; bits[1] = counter_pos + j * 3; final_and.push_back(add_xor(bits)); } vector<int> res; res.push_back(add_and(final_and)); add_not(res); }