Submission #778588

# Submission time Handle Problem Language Result Execution time Memory
778588 2023-07-10T12:51:56 Z andrej246 Vision Program (IOI19_vision) C++14
0 / 100
64 ms 18028 KB
#include "vision.h"
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,N) for(long long i = 0; (i) < (N); (i)++)
#define FORS(i,v,N) for(long long i = v; (i) < (N); (i)++)
#define FORI(i,v,N,inc) for(long long i = v; (i) < (N); (i)+=(inc))

#define NL '\n'
#define EL std::cout << NL

#define PRINTV(v) for(auto a:(v)) {std::cout << a << " ";};EL
#define PRINTVV(v) for(auto a:(v)) {PRINTV(a);}

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VLL;
typedef pair<ll,ll> PL;
typedef vector<PL> VPL;
typedef vector<VPL> VVPL;

void construct_network(int H, int W, int K) {
	std::vector<int> Ns;
	int z,o;
	if (H*W > 3) {
		z = add_and({0,1,2});
		o = add_not(z);
	} else {
        o = add_and({0,1});
		z = add_not(o);
	}
    vector<vector<int>> xinter0(8);
    vector<vector<int>> xinter1(8);
	vector<vector<int>> yinter0(8);
    vector<vector<int>> yinter1(8);
	int pow = 1;
	FOR(n,8) {
	    FOR(i,H*W) {
            if (((i%W)/pow) % 2) {
				xinter1[n].push_back(i);
			} else {
				xinter0[n].push_back(i);
			}
			if (((i/W)/pow) % 2) {
				yinter1[n].push_back(i);
			} else {
				yinter0[n].push_back(i);
			}
		}
		pow *= 2;
	}
	vector<vector<vector<int>>> xinter11(8,vector<vector<int>>(8));
	vector<vector<vector<int>>> yinter11(8,vector<vector<int>>(8));
	vector<vector<vector<int>>> xinter10(8,vector<vector<int>>(8));
	vector<vector<vector<int>>> yinter10(8,vector<vector<int>>(8));
	pow = 1;
	FOR(m,8) {
		FOR(n,8) {
			for(int i : xinter1[n]) {
				if (((i%W)/pow) % 2) {
					xinter11[m][n].push_back(i);
				}
			}
			for(int i : xinter0[n]) {
				if (((i%W)/pow) % 2) {
					xinter10[m][n].push_back(i);
				}
			}
		}
		pow *= 2;
	}
	pow = 1;
	FOR(m,8) {
		FOR(n,8) {
			for(int i : yinter1[n]) {
				if (((i/W)/pow) % 2) {
					yinter11[m][n].push_back(i);
				}
			}
			for(int i : yinter0[n]) {
				if (((i/W)/pow) % 2) {
					yinter10[m][n].push_back(i);
				}
			}
		}
		pow *= 2;
	}
	FOR(m,8) {
		FOR(n,8) {
			if (xinter11[m][n].size() == 0) {
				xinter11[m][n] = {z};
			}
			if (yinter11[m][n].size() == 0) {
				yinter11[m][n] = {z};
			}
			if (xinter10[m][n].size() == 0) {
				xinter10[m][n] = {z};
			}
			if (yinter10[m][n].size() == 0) {
				yinter10[m][n] = {z};
			}
		}
	}
	//PRINTV(xinter0[6]); EL;
	//PRINTVV(xinter1); EL;
	//PRINTVV(yinter0); EL;
	//PRINTVV(yinter1); EL;
	vector<int> x1(8);
	vector<int> x2(8);
	vector<int> y1(8);
	vector<int> y2(8);
	vector<int> xbreakbits;
	vector<int> ybreakbits;
	for(int i = 7; i >= 0; i--) {
		vector<int> i0 = xinter0[i];
		vector<int> i1 = xinter1[i];
		if (i0.size() == 0) i0 = {z};
		if (i1.size() == 0) i1 = {z};
		int is_diff = add_and({add_xor(i0),add_xor(i1)});
		int or_bit = add_or(i1);
		if (i == 7) {
			xbreakbits.push_back(add_or({is_diff}));
		} else {
			xbreakbits.push_back(add_and({add_not(add_or(xbreakbits)),is_diff}));
		}
		vector<int> disc_listA;
		vector<int> disc_listB;
		for(int j = 7; j >= i; j--) {
			disc_listA.push_back(add_and({add_or(xinter10[i][j]),xbreakbits[7-j]}));
			disc_listB.push_back(add_and({add_or(xinter11[i][j]),xbreakbits[7-j]}));
		}
		int discA = add_or(disc_listA);
		int discB = add_or(disc_listB);
		//vector<int> db = {is_diff,discA,discB};
		//print_vals(db);
		x1[i] = add_or({add_and({or_bit,add_not(is_diff)}),add_and({is_diff,discA})});
		x2[i] = add_or({add_and({or_bit,add_not(is_diff)}),add_and({is_diff,discB})});
	}
	for(int i = 7; i >= 0; i--) {
		vector<int> i0 = yinter0[i];
		vector<int> i1 = yinter1[i];
		if (i0.size() == 0) i0 = {z};
		if (i1.size() == 0) i1 = {z};
		int is_diff = add_and({add_xor(i0),add_xor(i1)});
		int or_bit = add_or(i1);
		if (i == 7) {
			ybreakbits.push_back(add_or({is_diff}));
		} else {
			ybreakbits.push_back(add_and({add_not(add_or(ybreakbits)),is_diff}));
		}
		vector<int> disc_listA;
		vector<int> disc_listB;
		for(int j = 7; j >= i; j--) {
			disc_listA.push_back(add_and({add_or(yinter10[i][j]),ybreakbits[7-j]}));
			disc_listB.push_back(add_and({add_or(yinter11[i][j]),ybreakbits[7-j]}));
		}
		int discA = add_or(disc_listA);
		int discB = add_or(disc_listB);
		//vector<int> db = {is_diff,discA,discB};
		//print_vals(db);
		y1[i] = add_or({add_and({or_bit,add_not(is_diff)}),add_and({is_diff,discA})});
		y2[i] = add_or({add_and({or_bit,add_not(is_diff)}),add_and({is_diff,discB})});
	}
	//print_vals(x1);
	//print_vals(x2);
	//print_vals(y1);
	//print_vals(y2);
	vector<int> rx1(9);
	vector<int> ry1(9);
	vector<int> dx(9);
	vector<int> dy(9);
	FOR(i,8) {
		rx1[i] = add_not(x1[i]);
		ry1[i] = add_not(y1[i]);
	}
	int c1 = z;
	FOR(i,8) {
		rx1[i] = add_xor({c1,o,rx1[i]});
        c1 = add_or({c1,rx1[i]});
	}
	c1 = z;
	FOR(i,8) {
		ry1[i] = add_xor({c1,o,ry1[i]});
        c1 = add_or({c1,ry1[i]});
	}
	rx1[8] = ry1[8] = o;
	int c = z;
	FOR(i,8) {
        dx[i] = add_xor({rx1[i],x2[i],c});
		c = add_or({add_and({rx1[i],x2[i]}),add_and({rx1[i],c}),add_and({c,x2[i]})});
	}
	dx[8] = add_xor({c,o});
	c = z;
	FOR(i,8) {
        dy[i] = add_xor({ry1[i],y2[i],c});
		c = add_or({add_and({ry1[i],y2[i]}),add_and({ry1[i],c}),add_and({c,y2[i]})});
	}
	dy[8] = add_xor({c,o});
	//print_vals(rx1);
	//print_vals(ry1);
	//print_vals(dx);
	//print_vals(dy);
	c = z;
	vector<int> dist(9);
	FOR(i,9) {
        dist[i] = add_xor({dx[i],dy[i],c});
		c = add_or({add_and({dx[i],dy[i]}),add_and({dx[i],c}),add_and({c,dy[i]})});
	}
	//print_vals(dist);
	vector<int> kdist;
	vector<int> pos;
	while(K) {
		kdist.push_back(K%2);
		K /= 2;
	}
	//PRINTV(kdist);
	FOR(i,(int)kdist.size()) {
        if (kdist[i]) {
			pos.push_back(dist[i]);
		} 
	}
	add_and(pos);
	
	//print_vals(xbreakbits);
	return;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB on inputs (0, 0), (0, 2), expected 0, but computed 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB on inputs (0, 0), (0, 2), expected 0, but computed 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB on inputs (0, 0), (0, 2), expected 0, but computed 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB on inputs (0, 0), (0, 2), expected 0, but computed 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 432 KB on inputs (0, 0), (0, 3), expected 0, but computed 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 17 ms 2604 KB Output is correct
4 Correct 18 ms 2624 KB Output is correct
5 Incorrect 17 ms 2636 KB on inputs (0, 0), (37, 28), expected 0, but computed 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 18028 KB WA in grader: Too many inputs
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB on inputs (0, 0), (0, 2), expected 0, but computed 1
2 Halted 0 ms 0 KB -