Submission #805897

#TimeUsernameProblemLanguageResultExecution timeMemory
805897math_rabbit_1028Vision Program (IOI19_vision)C++14
100 / 100
25 ms2764 KiB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
		
vector<int> Ns;

void construct_network(int H, int W, int K) {

	Ns.clear();
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) Ns.push_back(i * W + j);
	int one = add_or(Ns);
	int zero = add_not(W * H);

	//=================================================================//

	for (int i = 0; i < H; i++) {
		Ns.clear();
		for (int j = 0; j < W; j++) Ns.push_back(i * W + j);
		add_or(Ns);
	}

	int s = H * W + 2;

	Ns.clear();
	for (int i = 0; i < H; i++) Ns.push_back(s + i);
	add_xor(Ns);
	add_not(s + H);

	for (int i = 0; i < H; i++) add_and({s + i, s + H + 1});

	Ns.clear();
	for (int i = 0; i < H; i++) {
		Ns.push_back(s + H + 2 + i);
		add_xor(Ns);
	}

	//=================================================================//

	for (int j = 0; j < W; j++) {
		Ns.clear();
		for (int i = 0; i < H; i++) Ns.push_back(i * W + j);
		add_or(Ns);
	}

	int t = s + 3 * H + 2;

	Ns.clear();
	for (int i = 0; i < W; i++) Ns.push_back(t + i);
	add_xor(Ns);
	add_not(t + W);

	for (int i = 0; i < W; i++) add_and({t + i, t + W + 1});

	Ns.clear();
	for (int i = 0; i < W; i++) {
		Ns.push_back(t + W + 2 + i);
		add_xor(Ns);
	}

	//=================================================================//

	// [s + 2H + 2, s + 3H + 1], [t + 2W + 2, t + 3W + 1]
	int u = t + 3 * W + 2, x = 0;
	for (int i = 0; i < 10; i++) add_and({zero});
	for (int i = s + 2 * H + 2; i < s + 3 * H + 2; i++) {
		add_and({i});
		for (int j = 1; j < 10; j++) {
			add_and({u + 10 * x + j - 1, u + 10 * x + j + 9});
		}
		for (int j = 0; j < 10; j++) {
			add_xor({u + 10 * x + j, u + 10 * x + j + 10});
		}
		x += 2;
	}
	for (int i = t + 2 * W + 2; i < t + 3 * W + 2; i++) {
		add_and({i});
		for (int j = 1; j < 10; j++) {
			add_and({u + 10 * x + j - 1, u + 10 * x + j + 9});
		}
		for (int j = 0; j < 10; j++) {
			add_xor({u + 10 * x + j, u + 10 * x + j + 10});
		}
		x += 2;
	}

	//=================================================================//

	int v = u + 20 * H + 20 * W + 10;

	for (int j = 0; j < 10; j++) {
		if (K & (1<<j)) add_and({zero});
		else add_and({one});
	}

	for (int j = 0; j < 10; j++) add_xor({v + j, v + j - 10});
	Ns.clear();
	for (int j = 0; j < 10; j++) Ns.push_back(v + j + 10);
	add_and(Ns);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...