제출 #1159449

#제출 시각아이디문제언어결과실행 시간메모리
1159449gygVision Program (IOI19_vision)C++20
73 / 100
44 ms4088 KiB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define pii pair<int, int>
#define fir first 
#define sec second

int n, m, k;

int id(int i, int j) { return i * m + j; }
vec<int> up(int x) {
	vec<int> ans;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (i + j == x) ans.push_back(id(i, j));
	return ans;
}
vec<int> dwn(int x) {
	vec<int> ans;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (i - j == x) ans.push_back(id(i, j));
	return ans;
}
vec<int> rng(int l, int r, map<int, int>& x) {
	vec<int> ans;
	for (int i = l; i <= r; i++) ans.push_back(x[i]);
	return ans;
}

void construct_network(int _n, int _m, int _k) {
	n = _n, m = _m, k = _k;
	int nm = n * m - 1;

	map<int, int> up1, dwn1, up2, dwn2;
	for (int x = 0; x <= n + m - 2; x++) {
		add_or(up(x)), nm++;
		up1[x] = nm;
	}
	for (int x = -m + 1; x <= n - 1; x++) {
		add_or(dwn(x)), nm++;
		dwn1[x] = nm;
	}
	for (int x = 0; x <= n + m - 2; x++) {
		add_xor(up(x)), nm++;
		add_not(nm), nm++;
		add_and({nm, up1[x]}), nm++;
		up2[x] = nm;
	}
	for (int x = -m + 1; x <= n - 1; x++) {
		add_xor(dwn(x)), nm++;
		add_not(nm), nm++;
		add_and({nm, dwn1[x]}), nm++;
		dwn2[x] = nm;
	}

	vec<int> a1, a2, a_up, a_dwn;
	int a_all = 0;
	for (int l = 0; l <= n + m - 2; l++) {
		int r = l + k;
		if (r > n + m - 2) continue;
		add_or(rng(l, r, up1)), nm++;
		a1.push_back(nm);
		add_or(rng(l, r, up2)), nm++;
		a2.push_back(nm);
		add_xor(rng(l, r, up1)), nm++;
		add_not(nm), nm++;
		add_and({a1.back(), nm}), nm++;
		add_or({a2.back(), nm}), nm++;
		a_up.push_back(nm);
	} 
	for (int l = -m + 1; l <= n - 1; l++) {
		int r = l + k;
		if (r > n - 1) continue;
		add_or(rng(l, r, dwn1)), nm++;
		a1.push_back(nm);
		add_or(rng(l, r, dwn2)), nm++;
		a2.push_back(nm);
		add_xor(rng(l, r, dwn1)), nm++;
		add_not(nm), nm++;
		add_and({a1.back(), nm}), nm++;
		add_or({a2.back(), nm}), nm++;
		a_dwn.push_back(nm);
	}
	add_or(a_up), nm++;
	add_or(a_dwn), nm++;
	add_and({nm - 1, nm}), nm++;
	a_all = nm;

	if (k == 1) return;

	vec<int> b1, b2, b_up, b_dwn;
	int b_all = 0;
	for (int l = 0; l <= n + m - 2; l++) {
		int r = l + k - 1;
		if (r > n + m - 2) continue;
		add_or(rng(l, r, up1)), nm++;
		b1.push_back(nm);
		add_or(rng(l, r, up2)), nm++;
		b2.push_back(nm);
		add_xor(rng(l, r, up1)), nm++;
		add_not(nm), nm++;
		add_and({b1.back(), nm}), nm++;
		add_or({b2.back(), nm}), nm++;
		b_up.push_back(nm);
	}
	for (int l = -m + 1; l <= n - 1; l++) {
		int r = l + k - 1;
		if (r > n - 1) continue;
		add_or(rng(l, r, dwn1)), nm++;
		b1.push_back(nm);
		add_or(rng(l, r, dwn2)), nm++;
		b2.push_back(nm);
		add_xor(rng(l, r, dwn1)), nm++;
		add_not(nm), nm++;
		add_and({b1.back(), nm}), nm++;
		add_or({b2.back(), nm}), nm++;
		b_dwn.push_back(nm);
	}
	add_or(b_up), nm++;
	add_or(b_dwn), nm++;
	add_and({nm - 1, nm}), nm++;
	b_all = nm;

	// for (int x : a_up) cout << x << " ";
	// cout << endl;
	// for (int x : a_dwn) cout << x << " ";
	// cout << endl;
	// for (int x : b_up) cout << x << " ";
	// cout << endl;
	// for (int x : b_dwn) cout << x << " ";
	// cout << endl;

	add_not(b_all), nm++;
	add_and({a_all, nm}), nm++;
}
#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...