답안 #241605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241605 2020-06-24T17:38:47 Z mosesmayer Vision Program (IOI19_vision) C++17
100 / 100
65 ms 5496 KB
#include "vision.h"
#include <tuple>

using namespace std;

int H, W;
int coord(int i, int j) {
	return i * W + j;
};

vector<int> get_cells(int D, bool dir) {
	// dir is 1 if left diagonal (sum), 0 if right diagonal.
	vector<int> res;
	int start, stop, diff;
	if (dir) {
		start = D < W ? D : (D - W + 1) * W + (W - 1);
		stop = D < H ? D * W : (H - 1) * W + (D - H + 1);
		diff = W - 1;
	} else {
		start = D < W ? W - 1 - D : (D - W + 1) * W;
		stop = D < H ? (D + 1) * W - 1 : H * W - 1 - (D - H + 1);
		diff = W + 1;
	}
	for (; start <= stop; start += diff) {
		res.emplace_back(start);
		if (start == stop) break;
	}
	return res;
}

void construct_diagonals(bool dir, vector<int>& orv, vector<int>& xorv) {
	for (int i = 0; i <= H + W - 2; i++) {
		vector<int> cur = get_cells(i, dir);
		// printf("add %s squares: ", dir ? "left" : "right");
		// for (int i : cur) {
		// 	printf("%d ", i);
		// }
		// puts("");
		orv.emplace_back(add_or(cur));
		xorv.emplace_back(add_xor(cur));
	}
}

int test(const vector<int>& orv, const vector<int>& xorv, int D) {
	// tests if there are D consecutive diagonals which has 2 black.
	vector<int> cur_or(D), cur_xor(D), res;
	for (int i = 0, t = orv.size(); i < t; i++) {
		cur_or[i % D] = orv[i];
		cur_xor[i % D] = xorv[i];
		if (i >= D - 1)
			res.emplace_back(add_and({add_or(cur_or),
					         add_not(add_xor(cur_xor)) // odd iff exactly 1.
			}));
	}
	return add_or(res);
}

void construct_network(int H, int W, int K) {
	tie(::H, ::W) = {H, W};
//	std::vector<int> Ns;
//	Ns = {0, 1};
//	int a = add_and(Ns);
//	Ns = {0, a};
//	int b = add_or(Ns);
//	Ns = {0, 1, b};
//	int c = add_xor(Ns);
//	add_not(c);

	vector<int> left_diags_or, right_diags_or;
	vector<int> left_diags_xor, right_diags_xor;

	// Base diagonal processing
	construct_diagonals(1, left_diags_or, left_diags_xor);
	construct_diagonals(0, right_diags_or, right_diags_xor);

	// or -> 1 if has black pixel in diag, 0 otherwise
	// xor -> if 0 where or is 1, then 2 black in diag. if 1 then 1 black.
	// if consecutive diagonals, if xor of xor's = 1 then exactly 1 black
	// if or of or's = 1 then >= 1 black.
	// if xor of xor's = 0 then even num of blacks.
	// want or of or's = 1 and xor of xor's = 0.

	int k1val = add_and({test(left_diags_or, left_diags_xor, K + 1),
						test(right_diags_or,right_diags_xor, K + 1)});
	int kval = add_and({test(left_diags_or, left_diags_xor, K),
						test(right_diags_or,right_diags_xor, K)});
	// want k1val true and kval false.
	add_and({k1val, add_xor({kval, k1val})});
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 6 ms 512 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 6 ms 512 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 18 ms 1536 KB Output is correct
39 Correct 7 ms 512 KB Output is correct
40 Correct 7 ms 512 KB Output is correct
41 Correct 9 ms 768 KB Output is correct
42 Correct 7 ms 544 KB Output is correct
43 Correct 11 ms 896 KB Output is correct
44 Correct 17 ms 1536 KB Output is correct
45 Correct 19 ms 1664 KB Output is correct
46 Correct 17 ms 1408 KB Output is correct
47 Correct 10 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 640 KB Output is correct
2 Correct 15 ms 1152 KB Output is correct
3 Correct 14 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 14 ms 1024 KB Output is correct
7 Correct 13 ms 1024 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 12 ms 1024 KB Output is correct
11 Correct 14 ms 1152 KB Output is correct
12 Correct 14 ms 1152 KB Output is correct
13 Correct 12 ms 896 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 7 ms 640 KB Output is correct
16 Correct 12 ms 1024 KB Output is correct
17 Correct 14 ms 1152 KB Output is correct
18 Correct 14 ms 1152 KB Output is correct
19 Correct 12 ms 896 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 10 ms 768 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 10 ms 768 KB Output is correct
9 Correct 14 ms 1152 KB Output is correct
10 Correct 15 ms 1280 KB Output is correct
11 Correct 13 ms 1024 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 14 ms 1152 KB Output is correct
15 Correct 12 ms 1024 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 16 ms 1152 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 17 ms 1532 KB Output is correct
21 Correct 33 ms 2932 KB Output is correct
22 Correct 35 ms 2808 KB Output is correct
23 Correct 18 ms 1152 KB Output is correct
24 Correct 17 ms 1532 KB Output is correct
25 Correct 35 ms 3064 KB Output is correct
26 Correct 12 ms 1152 KB Output is correct
27 Correct 28 ms 2428 KB Output is correct
28 Correct 56 ms 4600 KB Output is correct
29 Correct 61 ms 5496 KB Output is correct
30 Correct 51 ms 4508 KB Output is correct
31 Correct 24 ms 2048 KB Output is correct
32 Correct 4 ms 256 KB Output is correct
33 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2300 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 9 ms 640 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 17 ms 1532 KB Output is correct
8 Correct 17 ms 1532 KB Output is correct
9 Correct 27 ms 2548 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 6 ms 512 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 18 ms 1536 KB Output is correct
39 Correct 7 ms 512 KB Output is correct
40 Correct 7 ms 512 KB Output is correct
41 Correct 9 ms 768 KB Output is correct
42 Correct 7 ms 544 KB Output is correct
43 Correct 11 ms 896 KB Output is correct
44 Correct 17 ms 1536 KB Output is correct
45 Correct 19 ms 1664 KB Output is correct
46 Correct 17 ms 1408 KB Output is correct
47 Correct 10 ms 768 KB Output is correct
48 Correct 7 ms 640 KB Output is correct
49 Correct 15 ms 1152 KB Output is correct
50 Correct 14 ms 1152 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 7 ms 640 KB Output is correct
53 Correct 14 ms 1024 KB Output is correct
54 Correct 13 ms 1024 KB Output is correct
55 Correct 6 ms 384 KB Output is correct
56 Correct 7 ms 640 KB Output is correct
57 Correct 12 ms 1024 KB Output is correct
58 Correct 14 ms 1152 KB Output is correct
59 Correct 14 ms 1152 KB Output is correct
60 Correct 12 ms 896 KB Output is correct
61 Correct 6 ms 384 KB Output is correct
62 Correct 7 ms 640 KB Output is correct
63 Correct 12 ms 1024 KB Output is correct
64 Correct 14 ms 1152 KB Output is correct
65 Correct 14 ms 1152 KB Output is correct
66 Correct 12 ms 896 KB Output is correct
67 Correct 6 ms 384 KB Output is correct
68 Correct 5 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 4 ms 256 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 7 ms 640 KB Output is correct
73 Correct 9 ms 768 KB Output is correct
74 Correct 10 ms 896 KB Output is correct
75 Correct 10 ms 768 KB Output is correct
76 Correct 6 ms 512 KB Output is correct
77 Correct 10 ms 768 KB Output is correct
78 Correct 14 ms 1152 KB Output is correct
79 Correct 15 ms 1280 KB Output is correct
80 Correct 13 ms 1024 KB Output is correct
81 Correct 8 ms 640 KB Output is correct
82 Correct 7 ms 640 KB Output is correct
83 Correct 14 ms 1152 KB Output is correct
84 Correct 12 ms 1024 KB Output is correct
85 Correct 5 ms 384 KB Output is correct
86 Correct 7 ms 640 KB Output is correct
87 Correct 16 ms 1152 KB Output is correct
88 Correct 5 ms 256 KB Output is correct
89 Correct 17 ms 1532 KB Output is correct
90 Correct 33 ms 2932 KB Output is correct
91 Correct 35 ms 2808 KB Output is correct
92 Correct 18 ms 1152 KB Output is correct
93 Correct 17 ms 1532 KB Output is correct
94 Correct 35 ms 3064 KB Output is correct
95 Correct 12 ms 1152 KB Output is correct
96 Correct 28 ms 2428 KB Output is correct
97 Correct 56 ms 4600 KB Output is correct
98 Correct 61 ms 5496 KB Output is correct
99 Correct 51 ms 4508 KB Output is correct
100 Correct 24 ms 2048 KB Output is correct
101 Correct 4 ms 256 KB Output is correct
102 Correct 4 ms 256 KB Output is correct
103 Correct 27 ms 2300 KB Output is correct
104 Correct 4 ms 256 KB Output is correct
105 Correct 9 ms 640 KB Output is correct
106 Correct 9 ms 768 KB Output is correct
107 Correct 7 ms 640 KB Output is correct
108 Correct 6 ms 640 KB Output is correct
109 Correct 17 ms 1532 KB Output is correct
110 Correct 17 ms 1532 KB Output is correct
111 Correct 27 ms 2548 KB Output is correct
112 Correct 5 ms 256 KB Output is correct
113 Correct 4 ms 256 KB Output is correct
114 Correct 52 ms 4592 KB Output is correct
115 Correct 5 ms 384 KB Output is correct
116 Correct 7 ms 640 KB Output is correct
117 Correct 28 ms 2176 KB Output is correct
118 Correct 27 ms 2428 KB Output is correct
119 Correct 65 ms 5236 KB Output is correct
120 Correct 59 ms 5236 KB Output is correct
121 Correct 60 ms 5364 KB Output is correct
122 Correct 64 ms 5364 KB Output is correct
123 Correct 27 ms 2420 KB Output is correct
124 Correct 54 ms 4724 KB Output is correct
125 Correct 59 ms 5364 KB Output is correct
126 Correct 60 ms 5364 KB Output is correct
127 Correct 50 ms 4472 KB Output is correct
128 Correct 24 ms 2048 KB Output is correct