Submission #823848

#TimeUsernameProblemLanguageResultExecution timeMemory
823848vjudge1Vision Program (IOI19_vision)C++17
66 / 100
10 ms1524 KiB
#include<bits/stdc++.h>
#include "vision.h"

using namespace std;

void construct_network(int H, int W, int K) {
	int cur = H * W;
	if(K == 1) {
		// H * W -> H * W + H - 1
		for(int i = 0; i < H; i++) {
			vector<int> Ns;
			for(int j = 0; j < W; j++)
				Ns.push_back(i * W + j);
			add_xor(Ns);
			cur++;
		}
		vector<int> Ns;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				Ns.push_back(i * W + j);
			}
		}
		// H * (W + 1)
		add_xor(Ns);
		cur++;
		Ns.clear();
		// (W + 1) * H + 1 -> (W + 1) * H + W
		for(int j = 0; j < W; j++) {
			vector<int> Ns;
			for(int i = 0; i < H; i++) {
				Ns.push_back(i * W + j);
			}
			add_xor(Ns);
			cur++;
		}
		int t = cur;
		for(int i = H * W; i < t - 1; i++) {
			add_and({i, i + 1});
			cur++;
		}
		for(int i = t; i < cur; i++) {
			Ns.push_back(i);
		}
		int Ch = cur;
		add_xor(Ns);
		cur++;
		Ns.clear();
		for(int i = H * W; i < H * (W + 1); i++) 
			Ns.push_back(i);
		add_or(Ns);
		cur++;
		Ns.clear();
		for(int i = (W + 1) * H + 1; i <= (W + 1) * H + W; i++) 
			Ns.push_back(i);
		add_or(Ns);
		cur++;
		add_xor({Ch + 1, Ch + 2});
		add_and({Ch, cur});
		return;
	}
	if(max(H, W) <= 30 || min(H, W) == 1) { 
		for(int x1 = 0; x1 < H; x1++) {
			for(int y1 = 0; y1 < W; y1++) {
				vector<int> Ns;
				for(int d = -K + 1; d <= K; d++) {
					int x2 = x1 + d, y2 = y1 + K - abs(d);
					if(x2 < 0 || x2 >= H || y2 < 0 || y2 >= W) continue;
					Ns.push_back(x2 * W + y2);
				}
				if(!Ns.empty()) {
					add_or(Ns);
					add_and({cur, x1 * W + y1});
					cur += 2;
				}
			}
		}
		vector<int> ns;
		for(int i = H * W + 1; i < cur; i += 2)
			ns.push_back(i);
		add_or(ns);
		return;
	}
	vector<int> ns;
	for(int x = 0; x <= K; x++) {
		int y = K - x;
		if(x < H && y < W) 
			ns.push_back(x * W + y);
	}
	add_or(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...