Submission #417562

#TimeUsernameProblemLanguageResultExecution timeMemory
417562Kevin_Zhang_TWVision Program (IOI19_vision)C++17
100 / 100
17 ms1860 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
#include "vision.h"

const int MAX_N = 300010;

vector<int> operator + (vector<int> a, vector<int> b) { a.insert(end(a), AI(b)); return a; }

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

	auto to_id = [&](int i, int j) {
		return i * W + j;
	};
	auto valid = [&](int i, int j) {
		return i >= 0 && i < H && j >= 0 && j < W;
	};


	vector<int> bits;
	{
		vector<int> f(H), pf(H), suf(H);
		for (int i = 0;i < H;++i) {
			vector<int> qp;
			for (int j = 0;j < W;++j)
				qp.pb(to_id(i, j));
			f[i] = add_or(qp);
		}
		for (int i = 0;i+1 < H;++i) {
			pf[i] = f[i];
			if (i) pf[i] = add_or({pf[i-1], pf[i]});
		}
		for (int i = H-1;i > 0;--i) {
			suf[i] = f[i];
			if (i+1 < H) suf[i] = add_or({suf[i+1], suf[i]});
		}
		for (int i = 0;i+1 < H;++i)
			bits.pb(add_and({pf[i], suf[i+1]}));
	}
	{
		vector<int> f(W), pf(W), suf(W);
		for (int i = 0;i < W;++i) {
			vector<int> qp;
			for (int j = 0;j < H;++j)
				qp.pb(to_id(j, i));
			f[i] = add_or(qp);
		}
		for (int i = 0;i+1 < W;++i) {
			pf[i] = f[i];
			if (i) pf[i] = add_or({pf[i-1], pf[i]});
		}
		for (int i = W-1;i > 0;--i) {
			suf[i] = f[i];
			if (i+1 < W) suf[i] = add_or({suf[i+1], suf[i]});
		}
		for (int i = 0;i+1 < W;++i)
			bits.pb(add_and({pf[i], suf[i+1]}));
	}
					
	int mxv = bits.size(), wid = __lg(mxv) + 1;
	int zero = add_xor({0, 0}), one = add_not(zero);

	vector<int> a(wid, zero), b(wid, zero);

	for (int i = 0;i < wid;++i)
		if (K>>i&1) b[i] = one;

	for (int i : bits) {
		for (int j = 0;j < wid;++j) {
			int ret = add_xor({i, a[j]});
			i = add_and({i, a[j]});
			a[j] = ret;
		}
	}

	vector<int> res;
	for (int i = 0;i < wid;++i)
		res.pb(add_xor({a[i], b[i]}));

	int x = add_or(res);
	add_not(x);

}

Compilation message (stderr)

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:28:7: warning: variable 'valid' set but not used [-Wunused-but-set-variable]
   28 |  auto valid = [&](int i, int j) {
      |       ^~~~~
#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...