Submission #1079700

# Submission time Handle Problem Language Result Execution time Memory
1079700 2024-08-28T21:38:43 Z BestCrazyNoob Vision Program (IOI19_vision) C++17
100 / 100
11 ms 2004 KB
#include "vision.h"
#include <vector>
#include <array>

using namespace std;

constexpr int BITS = 9;					// ############## TODO ###############à //
using BITINT = array<int, BITS>;

BITINT createInt(int x, int zero, int one) {
	BITINT res;
	for (int h = 0; h < BITS; h++) {
		res[h] = (x & (1 << h)) ? add_or({one}) : add_or({zero});
	}
	return res;
}

BITINT doCreateInt(int x, int zero) {
	BITINT res;
	for (int h = 0; h < BITS; h++) {
		res[h] = (x & (1 << h)) ? add_not(zero) : add_or({zero});
	}
	return res;
}

BITINT orInt(vector<BITINT> v) {
	BITINT res;
	for (int h = 0; h < BITS; h++) {
		vector<int> vh;
		for (BITINT b: v) vh.push_back(b[h]);
		res[h] = add_or(vh);
	}
	return res;
}

BITINT addInt(BITINT a, BITINT b) {
	BITINT res;
	res[0] = add_xor({a[0], b[0]});
	int carry = add_and({a[0], b[0]});
	for (int h = 1; h < BITS; h++) {
		res[h] = add_xor({a[h], b[h], carry});
		carry = add_or({
			add_and({a[h], b[h]}),
			add_and({carry, add_xor({a[h], b[h]})}
		)});
	}
	return res;
}

int equal(BITINT a, BITINT b) {
	vector<int> _xor;
	for (int h = 0; h < BITS; h++) {
		_xor.push_back(add_xor({a[h], b[h]}));
	}
	return add_not(add_or(_xor));
}

void construct_network(int H, int W, int K) {
	auto get = [&](int i, int j) {
		return W*i + j;
	};

	int zero = add_and({0, add_not(0)});

	vector<int> rowOr, ySweep(H), rySweep(H);
	vector<BITINT> ys1(H), ys2(H);
	for (int i = 0; i < H; i++) {
		vector<int> Y;
		for (int j = 0; j < W; j++) Y.push_back(get(i, j));
		rowOr.push_back(add_or(Y));
	}

	ySweep[0] = add_or({rowOr[0]});
	ys1[0] = createInt(0, zero, ySweep[0]);
	for (int i = 1; i < H; i++) {
		ySweep[i] = add_or({rowOr[i], ySweep[i-1]});
		ys1[i] = createInt(i, zero, add_xor({ySweep[i-1], ySweep[i]}));
	}

	rySweep[H-1] = add_or({rowOr[H-1]});
	ys2[H-1] = createInt(H-1, zero, rySweep[H-1]);
	for (int i = H-2; i >= 0; i--) {
		rySweep[i] = add_or({rowOr[i], rySweep[i+1]});
		ys2[i] = createInt(i, zero, add_xor({rySweep[i+1], rySweep[i]}));
	}

	vector<int> colOr, xSweep(W), rxSweep(W);
	vector<BITINT> xs1(W), xs2(W);
	for (int j = 0; j < W; j++) {
		vector<int> Y;
		for (int i = 0; i < H; i++) Y.push_back(get(i, j));
		colOr.push_back(add_or(Y));
	}

	xSweep[0] = add_or({colOr[0]});
	xs1[0] = createInt(0, zero, xSweep[0]);
	for (int j = 1; j < W; j++) {
		xSweep[j] = add_or({colOr[j], xSweep[j-1]});
		xs1[j] = createInt(j, zero, add_xor({xSweep[j-1], xSweep[j]}));
	}

	rxSweep[W-1] = add_or({colOr[W-1]});
	xs2[W-1] = createInt(W-1, zero, rxSweep[W-1]);
	for (int j = W-2; j >= 0; j--) {
		rxSweep[j] = add_or({colOr[j], rxSweep[j+1]});
		xs2[j] = createInt(j, zero, add_xor({rxSweep[j+1], rxSweep[j]}));
	}

	BITINT y1 = orInt(ys1);
	BITINT y2 = orInt(ys2);
	BITINT x1 = orInt(xs1);
	BITINT x2 = orInt(xs2);

	equal(addInt(addInt(x1, y1), doCreateInt(K, zero)), addInt(x2, y2));
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 420 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 420 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 420 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 420 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 420 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 420 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 3 ms 984 KB Output is correct
39 Correct 1 ms 644 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 996 KB Output is correct
44 Correct 3 ms 984 KB Output is correct
45 Correct 3 ms 984 KB Output is correct
46 Correct 3 ms 984 KB Output is correct
47 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 2 ms 728 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 3 ms 804 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 728 KB Output is correct
13 Correct 2 ms 828 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 984 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 680 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 880 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 788 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 6 ms 1240 KB Output is correct
21 Correct 5 ms 1368 KB Output is correct
22 Correct 6 ms 1372 KB Output is correct
23 Correct 5 ms 1368 KB Output is correct
24 Correct 4 ms 1372 KB Output is correct
25 Correct 5 ms 1196 KB Output is correct
26 Correct 6 ms 1368 KB Output is correct
27 Correct 9 ms 2004 KB Output is correct
28 Correct 9 ms 2000 KB Output is correct
29 Correct 9 ms 1748 KB Output is correct
30 Correct 8 ms 2004 KB Output is correct
31 Correct 8 ms 2004 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2000 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 3 ms 728 KB Output is correct
7 Correct 5 ms 1368 KB Output is correct
8 Correct 5 ms 1368 KB Output is correct
9 Correct 8 ms 2000 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 420 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 360 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 420 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 3 ms 984 KB Output is correct
39 Correct 1 ms 644 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 996 KB Output is correct
44 Correct 3 ms 984 KB Output is correct
45 Correct 3 ms 984 KB Output is correct
46 Correct 3 ms 984 KB Output is correct
47 Correct 3 ms 980 KB Output is correct
48 Correct 2 ms 728 KB Output is correct
49 Correct 2 ms 728 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 3 ms 804 KB Output is correct
52 Correct 2 ms 728 KB Output is correct
53 Correct 2 ms 728 KB Output is correct
54 Correct 2 ms 728 KB Output is correct
55 Correct 2 ms 728 KB Output is correct
56 Correct 2 ms 724 KB Output is correct
57 Correct 2 ms 724 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 2 ms 728 KB Output is correct
60 Correct 2 ms 828 KB Output is correct
61 Correct 2 ms 728 KB Output is correct
62 Correct 2 ms 728 KB Output is correct
63 Correct 3 ms 728 KB Output is correct
64 Correct 2 ms 728 KB Output is correct
65 Correct 2 ms 728 KB Output is correct
66 Correct 2 ms 728 KB Output is correct
67 Correct 2 ms 984 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 680 KB Output is correct
73 Correct 2 ms 732 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 2 ms 600 KB Output is correct
76 Correct 2 ms 604 KB Output is correct
77 Correct 3 ms 860 KB Output is correct
78 Correct 3 ms 896 KB Output is correct
79 Correct 2 ms 856 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 2 ms 880 KB Output is correct
82 Correct 2 ms 728 KB Output is correct
83 Correct 2 ms 728 KB Output is correct
84 Correct 2 ms 724 KB Output is correct
85 Correct 2 ms 724 KB Output is correct
86 Correct 2 ms 728 KB Output is correct
87 Correct 2 ms 788 KB Output is correct
88 Correct 2 ms 728 KB Output is correct
89 Correct 6 ms 1240 KB Output is correct
90 Correct 5 ms 1368 KB Output is correct
91 Correct 6 ms 1372 KB Output is correct
92 Correct 5 ms 1368 KB Output is correct
93 Correct 4 ms 1372 KB Output is correct
94 Correct 5 ms 1196 KB Output is correct
95 Correct 6 ms 1368 KB Output is correct
96 Correct 9 ms 2004 KB Output is correct
97 Correct 9 ms 2000 KB Output is correct
98 Correct 9 ms 1748 KB Output is correct
99 Correct 8 ms 2004 KB Output is correct
100 Correct 8 ms 2004 KB Output is correct
101 Correct 1 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 8 ms 2000 KB Output is correct
104 Correct 1 ms 348 KB Output is correct
105 Correct 1 ms 604 KB Output is correct
106 Correct 3 ms 860 KB Output is correct
107 Correct 2 ms 728 KB Output is correct
108 Correct 3 ms 728 KB Output is correct
109 Correct 5 ms 1368 KB Output is correct
110 Correct 5 ms 1368 KB Output is correct
111 Correct 8 ms 2000 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 0 ms 348 KB Output is correct
114 Correct 8 ms 1748 KB Output is correct
115 Correct 2 ms 728 KB Output is correct
116 Correct 2 ms 808 KB Output is correct
117 Correct 5 ms 1368 KB Output is correct
118 Correct 5 ms 1368 KB Output is correct
119 Correct 8 ms 1748 KB Output is correct
120 Correct 8 ms 1748 KB Output is correct
121 Correct 8 ms 1748 KB Output is correct
122 Correct 8 ms 1744 KB Output is correct
123 Correct 10 ms 1748 KB Output is correct
124 Correct 11 ms 1748 KB Output is correct
125 Correct 8 ms 1748 KB Output is correct
126 Correct 7 ms 2000 KB Output is correct
127 Correct 8 ms 2004 KB Output is correct
128 Correct 8 ms 2004 KB Output is correct