답안 #819396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819396 2023-08-10T10:15:31 Z andrey27_sm Vision Program (IOI19_vision) C++17
100 / 100
22 ms 2928 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
int add_and(std::vector<int> Ns);

int add_or(std::vector<int> Ns);

int add_xor(std::vector<int> Ns);

int add_not(int N);


void construct_network(int H, int W, int K){
	// get_ver_or
	int BIT_NUM = 9;
	
	//int ZERO = add_and({0,1,2});
	int ZERO;
	if(H*W-1 >= 2) ZERO = add_and({0,1,2});
	else{
		if(K == 1) add_and({0,1});
		else add_not(0);
		return;
	}
	vector<int> dist_vert(BIT_NUM);
	vector<int> dist_hori(BIT_NUM);
	{
		vector<int> num_ones;
		for (int i = 0; i < W; ++i)
		{
			vector<int> tmp;
			for (int j = 0; j < H; ++j)
			{
				tmp.push_back(j*W+i);
			}
			num_ones.push_back(add_or(tmp));
		}
		vector<vector<int>> bits_to_next(W,vector<int>(BIT_NUM));
		for (int i = 0; i < W; ++i)
		{
			for (int bit = 0; bit < BIT_NUM; ++bit)
			{
				vector<int> tmp;
				for (int j = i+1; j < W; ++j)
				{
					int dist = j-i;
					if((dist>>bit)&1) tmp.push_back(num_ones[j]);
				}
				if(tmp.size()) bits_to_next[i][bit] = add_or(tmp);
				else bits_to_next[i][bit] = ZERO;
			}
		}
		vector<vector<int>> bits_to_next_anded(W,vector<int>(BIT_NUM));
		for (int i = 0; i < W; ++i)
		{
			for (int bit = 0; bit < BIT_NUM; ++bit)
			{
				bits_to_next_anded[i][bit] = add_and({bits_to_next[i][bit],num_ones[i]});
			}
		}
		for (int bit = 0; bit < BIT_NUM; ++bit)
		{
			vector<int> tmp;
			for (int i = 0; i < W; ++i)
			{
				tmp.push_back(bits_to_next_anded[i][bit]);
			}
			dist_vert[bit] = add_or(tmp);
		}
	}
	{
		vector<int> num_ones;
		for (int i = 0; i < H; ++i)
		{
			vector<int> tmp;
			for (int j = 0; j < W; ++j)
			{
				tmp.push_back(i*W+j);
			}
			num_ones.push_back(add_or(tmp));
		}
		vector<vector<int>> bits_to_next(H,vector<int>(BIT_NUM));
		for (int i = 0; i < H; ++i)
		{
			for (int bit = 0; bit < BIT_NUM; ++bit)
			{
				vector<int> tmp;
				for (int j = i+1; j < H; ++j)
				{
					int dist = j-i;
					if((dist>>bit)&1) tmp.push_back(num_ones[j]);
				}
				if(tmp.size()) bits_to_next[i][bit] = add_or(tmp);
				else bits_to_next[i][bit] = ZERO;
			}
		}

		vector<vector<int>> bits_to_next_anded(H,vector<int>(BIT_NUM));
		for (int i = 0; i < H; ++i)
		{
			for (int bit = 0; bit < BIT_NUM; ++bit)
			{
				bits_to_next_anded[i][bit] = add_and({bits_to_next[i][bit],num_ones[i]});
			}
		}
		for (int bit = 0; bit < BIT_NUM; ++bit)
		{
			vector<int> tmp;
			for (int i = 0; i < H; ++i)
			{
				tmp.push_back(bits_to_next_anded[i][bit]);
			}
			dist_hori[bit] = add_or(tmp);
		}
	}
	vector<int> delta(BIT_NUM,ZERO);
	vector<int> ans(BIT_NUM);
	for (int i = 0; i < BIT_NUM; ++i)
	{
		ans[i] = add_xor({delta[i],dist_hori[i],dist_vert[i]});
		if(i != BIT_NUM-1){
			int tmp_and = add_and({delta[i],dist_hori[i],dist_vert[i]});
			int tmp_not = add_not(ans[i]);
			int tmp_or = add_or({delta[i],dist_hori[i],dist_vert[i]});
			int tmp_or2 = add_or({tmp_not,tmp_and});
			delta[i+1] = add_and({tmp_or,tmp_or2});
		}
	}

	vector<int> ans_check(BIT_NUM);
	for (int i = 0; i < BIT_NUM; ++i)
	{
		int target = (K>>i)&1;
		if(target) ans_check[i] = add_or({ans[i]});
		else ans_check[i] = add_not(ans[i]);
	}

	int ans_end = add_and(ans_check);
}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:139:6: warning: unused variable 'ans_end' [-Wunused-variable]
  139 |  int ans_end = add_and(ans_check);
      |      ^~~~~~~
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 1 ms 212 KB Output is correct
27 Correct 1 ms 304 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 1 ms 212 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 340 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 304 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 1 ms 212 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 340 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 304 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 6 ms 932 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 3 ms 536 KB Output is correct
41 Correct 5 ms 768 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 5 ms 980 KB Output is correct
46 Correct 7 ms 980 KB Output is correct
47 Correct 5 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1108 KB Output is correct
2 Correct 7 ms 1104 KB Output is correct
3 Correct 6 ms 1128 KB Output is correct
4 Correct 8 ms 1108 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 6 ms 1004 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 6 ms 1064 KB Output is correct
11 Correct 6 ms 1108 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 6 ms 1108 KB Output is correct
14 Correct 7 ms 1112 KB Output is correct
15 Correct 7 ms 1108 KB Output is correct
16 Correct 6 ms 1108 KB Output is correct
17 Correct 6 ms 1048 KB Output is correct
18 Correct 6 ms 1108 KB Output is correct
19 Correct 6 ms 1108 KB Output is correct
20 Correct 6 ms 1128 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
12 Correct 5 ms 852 KB Output is correct
13 Correct 6 ms 1052 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 7 ms 1108 KB Output is correct
17 Correct 6 ms 1112 KB Output is correct
18 Correct 7 ms 1108 KB Output is correct
19 Correct 6 ms 1080 KB Output is correct
20 Correct 11 ms 1872 KB Output is correct
21 Correct 13 ms 1872 KB Output is correct
22 Correct 13 ms 1872 KB Output is correct
23 Correct 11 ms 1884 KB Output is correct
24 Correct 11 ms 1872 KB Output is correct
25 Correct 11 ms 1788 KB Output is correct
26 Correct 11 ms 1744 KB Output is correct
27 Correct 18 ms 2820 KB Output is correct
28 Correct 18 ms 2868 KB Output is correct
29 Correct 21 ms 2884 KB Output is correct
30 Correct 18 ms 2896 KB Output is correct
31 Correct 18 ms 2820 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2896 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 1108 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 10 ms 1872 KB Output is correct
8 Correct 13 ms 1800 KB Output is correct
9 Correct 18 ms 2908 KB Output is correct
10 Correct 0 ms 212 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 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 1 ms 212 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 340 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 304 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 312 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 6 ms 932 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 3 ms 536 KB Output is correct
41 Correct 5 ms 768 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 5 ms 980 KB Output is correct
46 Correct 7 ms 980 KB Output is correct
47 Correct 5 ms 992 KB Output is correct
48 Correct 6 ms 1108 KB Output is correct
49 Correct 7 ms 1104 KB Output is correct
50 Correct 6 ms 1128 KB Output is correct
51 Correct 8 ms 1108 KB Output is correct
52 Correct 6 ms 1108 KB Output is correct
53 Correct 6 ms 1108 KB Output is correct
54 Correct 6 ms 1004 KB Output is correct
55 Correct 6 ms 1108 KB Output is correct
56 Correct 6 ms 1108 KB Output is correct
57 Correct 6 ms 1064 KB Output is correct
58 Correct 6 ms 1108 KB Output is correct
59 Correct 8 ms 1108 KB Output is correct
60 Correct 6 ms 1108 KB Output is correct
61 Correct 7 ms 1112 KB Output is correct
62 Correct 7 ms 1108 KB Output is correct
63 Correct 6 ms 1108 KB Output is correct
64 Correct 6 ms 1048 KB Output is correct
65 Correct 6 ms 1108 KB Output is correct
66 Correct 6 ms 1108 KB Output is correct
67 Correct 6 ms 1128 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 3 ms 596 KB Output is correct
73 Correct 3 ms 724 KB Output is correct
74 Correct 3 ms 724 KB Output is correct
75 Correct 3 ms 724 KB Output is correct
76 Correct 3 ms 724 KB Output is correct
77 Correct 4 ms 852 KB Output is correct
78 Correct 4 ms 852 KB Output is correct
79 Correct 4 ms 852 KB Output is correct
80 Correct 4 ms 852 KB Output is correct
81 Correct 5 ms 852 KB Output is correct
82 Correct 6 ms 1052 KB Output is correct
83 Correct 6 ms 1108 KB Output is correct
84 Correct 6 ms 1108 KB Output is correct
85 Correct 7 ms 1108 KB Output is correct
86 Correct 6 ms 1112 KB Output is correct
87 Correct 7 ms 1108 KB Output is correct
88 Correct 6 ms 1080 KB Output is correct
89 Correct 11 ms 1872 KB Output is correct
90 Correct 13 ms 1872 KB Output is correct
91 Correct 13 ms 1872 KB Output is correct
92 Correct 11 ms 1884 KB Output is correct
93 Correct 11 ms 1872 KB Output is correct
94 Correct 11 ms 1788 KB Output is correct
95 Correct 11 ms 1744 KB Output is correct
96 Correct 18 ms 2820 KB Output is correct
97 Correct 18 ms 2868 KB Output is correct
98 Correct 21 ms 2884 KB Output is correct
99 Correct 18 ms 2896 KB Output is correct
100 Correct 18 ms 2820 KB Output is correct
101 Correct 1 ms 212 KB Output is correct
102 Correct 1 ms 304 KB Output is correct
103 Correct 22 ms 2896 KB Output is correct
104 Correct 0 ms 212 KB Output is correct
105 Correct 3 ms 724 KB Output is correct
106 Correct 5 ms 852 KB Output is correct
107 Correct 6 ms 1108 KB Output is correct
108 Correct 6 ms 1108 KB Output is correct
109 Correct 10 ms 1872 KB Output is correct
110 Correct 13 ms 1800 KB Output is correct
111 Correct 18 ms 2908 KB Output is correct
112 Correct 0 ms 212 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 18 ms 2896 KB Output is correct
115 Correct 6 ms 1108 KB Output is correct
116 Correct 8 ms 1108 KB Output is correct
117 Correct 11 ms 1836 KB Output is correct
118 Correct 13 ms 1764 KB Output is correct
119 Correct 18 ms 2796 KB Output is correct
120 Correct 17 ms 2896 KB Output is correct
121 Correct 21 ms 2836 KB Output is correct
122 Correct 20 ms 2896 KB Output is correct
123 Correct 18 ms 2896 KB Output is correct
124 Correct 18 ms 2896 KB Output is correct
125 Correct 18 ms 2896 KB Output is correct
126 Correct 18 ms 2788 KB Output is correct
127 Correct 18 ms 2904 KB Output is correct
128 Correct 18 ms 2928 KB Output is correct