답안 #596874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596874 2022-07-15T08:28:04 Z Temmie Vision Program (IOI19_vision) C++17
100 / 100
66 ms 6648 KB
#include "vision.h"
#include <bits/stdc++.h>

struct Diag {
	std::vector <std::pair <int, int>> a;
	Diag(const std::set <std::pair <int, int>>& st) {
		for (const auto& p : st) {
			a.emplace_back(p);
		}
	}
	int ind_or;
	int ind_xor;
	int ind_not_xor;
	int ind_has_two;
};

constexpr bool ok(int i, int j, int n, int m) {
	return i >= 0 && j >= 0 && i < n && j < m;
}

std::vector <int> conv(int m, const std::vector <std::pair <int, int>>& a) {
	std::vector <int> res(a.size());
	for (int i = 0; i < (int) a.size(); i++) {
		res[i] = a[i].first * m + a[i].second;
	}
	return res;
}

void construct_network(int n, int m, int k) {
	std::vector <Diag> up, down;
	{
		std::set <std::pair <int, int>> st;
		st.insert({ 0, 0 });
		while (st.size()) {
			down.push_back(Diag(st));
			std::set <std::pair <int, int>> stt;
			for (auto p : st) {
				if (ok(p.first + 1, p.second, n, m)) stt.insert({ p.first + 1, p.second });
				if (ok(p.first, p.second + 1, n, m)) stt.insert({ p.first, p.second + 1 });
			}
			st = stt;
		}
	}
	{
		std::set <std::pair <int, int>> st;
		st.insert({ n - 1, 0 });
		while (st.size()) {
			up.push_back(Diag(st));
			std::set <std::pair <int, int>> stt;
			for (auto p : st) {
				if (ok(p.first - 1, p.second, n, m)) stt.insert({ p.first - 1, p.second });
				if (ok(p.first, p.second + 1, n, m)) stt.insert({ p.first, p.second + 1 });
			}
			st = stt;
		}
	}
	for (Diag& d : down) {
		d.ind_or = add_or(conv(m, d.a));
		d.ind_xor = add_xor(conv(m, d.a));
		d.ind_not_xor = add_not(d.ind_xor);
		d.ind_has_two = add_and({ d.ind_or, d.ind_not_xor });
	}
	for (Diag& d : up) {
		d.ind_or = add_or(conv(m, d.a));
		d.ind_xor = add_xor(conv(m, d.a));
		d.ind_not_xor = add_not(d.ind_xor);
		d.ind_has_two = add_and({ d.ind_or, d.ind_not_xor });
	}
	//{ not xor { or } } and { or }
	//or
	//or { d.ind_has_two }
	auto go = [] (const std::vector <Diag>& diag, int kk) -> int {
		std::vector <int> inds;
		std::vector <Diag> cur;
		for (const Diag& d : diag) {
			cur.push_back(d);
			if ((int) cur.size() > kk) {
				cur.erase(cur.begin());
			}
			assert((int) cur.size() <= kk);
			if ((int) cur.size() == kk) {
				std::vector <int> idx;
				for (const Diag& dd : cur) {
					idx.push_back(dd.ind_or);
				}
				int ind_or = add_or(idx);
				int ind_xor = add_xor(idx);
				//int ind_not_xor = add_not(ind_xor);
				//int ind_and = add_and({ ind_not_xor, ind_or });
				int ind_and = add_xor({ ind_or, ind_xor });
				//idx.clear();
				//for (const Diag& dd : cur) {
					//idx.push_back(dd.ind_has_two);
				//}
				//int ind_h2_or = add_or(idx);
				//inds.push_back(add_or({ ind_and, ind_h2_or }));
				inds.push_back(ind_and);
			}
		}
		std::vector <int> all_ind_h2_or;
		for (const Diag& d : diag) {
			all_ind_h2_or.push_back(d.ind_has_two);
		}
		int ind_h2_or = add_or(all_ind_h2_or);
		inds.push_back(ind_h2_or);
		return add_or(inds);
	};
	int ind_kp1_up = go(up, k + 1);
	int ind_kp1_down = go(down, k + 1);
	int ind_kp0_up = go(up, k);
	int ind_kp0_down = go(down, k);
	
	int ind_kp1_both = add_and({ ind_kp1_up, ind_kp1_down });
	int ind_kp0_both = add_and({ ind_kp0_up, ind_kp0_down });
	
	int ind_kp0_not = add_not(ind_kp0_both);
	
	add_and({ ind_kp1_both, ind_kp0_not });
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 284 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 284 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 284 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 14 ms 1748 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 5 ms 852 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 8 ms 1236 KB Output is correct
44 Correct 14 ms 1756 KB Output is correct
45 Correct 18 ms 1876 KB Output is correct
46 Correct 13 ms 1748 KB Output is correct
47 Correct 7 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 8 ms 1108 KB Output is correct
3 Correct 9 ms 1112 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 8 ms 1108 KB Output is correct
7 Correct 11 ms 1108 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 8 ms 1032 KB Output is correct
11 Correct 9 ms 1236 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 9 ms 980 KB Output is correct
14 Correct 2 ms 472 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 7 ms 1112 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 10 ms 1108 KB Output is correct
19 Correct 7 ms 972 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 14 ms 1236 KB Output is correct
10 Correct 11 ms 1396 KB Output is correct
11 Correct 12 ms 1236 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 8 ms 1108 KB Output is correct
15 Correct 7 ms 1068 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 9 ms 1108 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 16 ms 2000 KB Output is correct
21 Correct 32 ms 3580 KB Output is correct
22 Correct 28 ms 3428 KB Output is correct
23 Correct 14 ms 1864 KB Output is correct
24 Correct 16 ms 1936 KB Output is correct
25 Correct 31 ms 3580 KB Output is correct
26 Correct 14 ms 1876 KB Output is correct
27 Correct 30 ms 3444 KB Output is correct
28 Correct 65 ms 5688 KB Output is correct
29 Correct 58 ms 6540 KB Output is correct
30 Correct 49 ms 5792 KB Output is correct
31 Correct 34 ms 3412 KB Output is correct
32 Correct 1 ms 400 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 3476 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 6 ms 932 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 15 ms 1928 KB Output is correct
8 Correct 17 ms 2000 KB Output is correct
9 Correct 31 ms 3372 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 284 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 14 ms 1748 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 5 ms 852 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 8 ms 1236 KB Output is correct
44 Correct 14 ms 1756 KB Output is correct
45 Correct 18 ms 1876 KB Output is correct
46 Correct 13 ms 1748 KB Output is correct
47 Correct 7 ms 1108 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 8 ms 1108 KB Output is correct
50 Correct 9 ms 1112 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 8 ms 1108 KB Output is correct
54 Correct 11 ms 1108 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 8 ms 1032 KB Output is correct
58 Correct 9 ms 1236 KB Output is correct
59 Correct 10 ms 1108 KB Output is correct
60 Correct 9 ms 980 KB Output is correct
61 Correct 2 ms 472 KB Output is correct
62 Correct 3 ms 596 KB Output is correct
63 Correct 7 ms 1112 KB Output is correct
64 Correct 8 ms 1108 KB Output is correct
65 Correct 10 ms 1108 KB Output is correct
66 Correct 7 ms 972 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 3 ms 724 KB Output is correct
73 Correct 5 ms 852 KB Output is correct
74 Correct 6 ms 852 KB Output is correct
75 Correct 6 ms 724 KB Output is correct
76 Correct 3 ms 596 KB Output is correct
77 Correct 5 ms 852 KB Output is correct
78 Correct 14 ms 1236 KB Output is correct
79 Correct 11 ms 1396 KB Output is correct
80 Correct 12 ms 1236 KB Output is correct
81 Correct 5 ms 724 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 8 ms 1108 KB Output is correct
84 Correct 7 ms 1068 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 2 ms 596 KB Output is correct
87 Correct 9 ms 1108 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 16 ms 2000 KB Output is correct
90 Correct 32 ms 3580 KB Output is correct
91 Correct 28 ms 3428 KB Output is correct
92 Correct 14 ms 1864 KB Output is correct
93 Correct 16 ms 1936 KB Output is correct
94 Correct 31 ms 3580 KB Output is correct
95 Correct 14 ms 1876 KB Output is correct
96 Correct 30 ms 3444 KB Output is correct
97 Correct 65 ms 5688 KB Output is correct
98 Correct 58 ms 6540 KB Output is correct
99 Correct 49 ms 5792 KB Output is correct
100 Correct 34 ms 3412 KB Output is correct
101 Correct 1 ms 400 KB Output is correct
102 Correct 1 ms 296 KB Output is correct
103 Correct 37 ms 3476 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 3 ms 688 KB Output is correct
106 Correct 6 ms 932 KB Output is correct
107 Correct 2 ms 596 KB Output is correct
108 Correct 2 ms 596 KB Output is correct
109 Correct 15 ms 1928 KB Output is correct
110 Correct 17 ms 2000 KB Output is correct
111 Correct 31 ms 3372 KB Output is correct
112 Correct 1 ms 300 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 52 ms 5712 KB Output is correct
115 Correct 2 ms 468 KB Output is correct
116 Correct 2 ms 596 KB Output is correct
117 Correct 23 ms 2772 KB Output is correct
118 Correct 26 ms 2848 KB Output is correct
119 Correct 59 ms 6472 KB Output is correct
120 Correct 56 ms 6472 KB Output is correct
121 Correct 55 ms 6572 KB Output is correct
122 Correct 66 ms 6648 KB Output is correct
123 Correct 31 ms 3472 KB Output is correct
124 Correct 52 ms 5736 KB Output is correct
125 Correct 58 ms 6644 KB Output is correct
126 Correct 57 ms 6576 KB Output is correct
127 Correct 56 ms 5736 KB Output is correct
128 Correct 29 ms 3388 KB Output is correct