답안 #778699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778699 2023-07-10T15:07:04 Z andrej246 Vision Program (IOI19_vision) C++14
59 / 100
67 ms 17920 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);}

#define print_vals(v)

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 = {or_bit,is_diff,discA,discB};
		//print_vals(db);
		//print_vals(i1);
		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);
	print_vals(xbreakbits);
	print_vals(ybreakbits);
	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});
	dx[8] = dy[8] = z;
	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,pos2;
	while(K) {
		kdist.push_back(K%2);
		K /= 2;
	}
	//PRINTV(kdist);
	FOR(i,9) {
        if (i < (int)kdist.size() && kdist[i]) {
			pos.push_back(dist[i]);
		} else {
            pos2.push_back(dist[i]);
		}
	}
	if (pos.size() == 0) {
		pos = {z};
	} else if (pos2.size() == 0) {
		pos2 = {z};
	}
	print_vals(pos);
	print_vals(pos2);
	add_and({add_and(pos),add_not(add_or(pos2))});
	
	//print_vals(xbreakbits);
	return;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 6 ms 864 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 7 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
35 Correct 7 ms 852 KB Output is correct
36 Correct 5 ms 852 KB Output is correct
37 Correct 5 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 6 ms 864 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 7 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
35 Correct 7 ms 852 KB Output is correct
36 Correct 5 ms 852 KB Output is correct
37 Correct 5 ms 852 KB Output is correct
38 Correct 64 ms 8780 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 1 ms 300 KB Output is correct
41 Correct 29 ms 4452 KB Output is correct
42 Correct 30 ms 4428 KB Output is correct
43 Correct 59 ms 8836 KB Output is correct
44 Correct 59 ms 8824 KB Output is correct
45 Correct 60 ms 8784 KB Output is correct
46 Correct 61 ms 8768 KB Output is correct
47 Correct 67 ms 8760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 452 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 464 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 20 ms 2588 KB Output is correct
4 Correct 17 ms 2644 KB Output is correct
5 Correct 17 ms 2676 KB Output is correct
6 Correct 17 ms 2644 KB Output is correct
7 Correct 17 ms 2644 KB Output is correct
8 Correct 35 ms 5212 KB Output is correct
9 Correct 41 ms 5196 KB Output is correct
10 Correct 35 ms 5204 KB Output is correct
11 Correct 44 ms 5268 KB Output is correct
12 Correct 34 ms 5264 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Incorrect 35 ms 11244 KB WA in grader: Too many inputs
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 17920 KB WA in grader: Too many inputs
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 6 ms 864 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 7 ms 852 KB Output is correct
34 Correct 7 ms 852 KB Output is correct
35 Correct 7 ms 852 KB Output is correct
36 Correct 5 ms 852 KB Output is correct
37 Correct 5 ms 852 KB Output is correct
38 Correct 64 ms 8780 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 1 ms 300 KB Output is correct
41 Correct 29 ms 4452 KB Output is correct
42 Correct 30 ms 4428 KB Output is correct
43 Correct 59 ms 8836 KB Output is correct
44 Correct 59 ms 8824 KB Output is correct
45 Correct 60 ms 8784 KB Output is correct
46 Correct 61 ms 8768 KB Output is correct
47 Correct 67 ms 8760 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 2 ms 452 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 468 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 2 ms 468 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 2 ms 464 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 2 ms 468 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 20 ms 2588 KB Output is correct
73 Correct 17 ms 2644 KB Output is correct
74 Correct 17 ms 2676 KB Output is correct
75 Correct 17 ms 2644 KB Output is correct
76 Correct 17 ms 2644 KB Output is correct
77 Correct 35 ms 5212 KB Output is correct
78 Correct 41 ms 5196 KB Output is correct
79 Correct 35 ms 5204 KB Output is correct
80 Correct 44 ms 5268 KB Output is correct
81 Correct 34 ms 5264 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 2 ms 468 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 2 ms 468 KB Output is correct
87 Correct 2 ms 468 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Incorrect 35 ms 11244 KB WA in grader: Too many inputs
90 Halted 0 ms 0 KB -