답안 #145459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145459 2019-08-19T23:31:07 Z kingpig9 Vision Program (IOI19_vision) C++14
100 / 100
39 ms 4344 KB
#include <bits/stdc++.h>
#include "vision.h"

using namespace std;
const int MAXN = 410;

int N, M, K;
int ncoord, npair;
vector<int> xtoy[MAXN], _ytox[MAXN], *ytox;
int xmin, xmax, ymin, ymax;

//position of x, y in the grid
//precondition: y is in xtoy[x]
int getgrid (int x, int y) {
	if ((x & 1) != (y & 1)) {
		assert(!"x and y have different parity");
	}
	int i = (x + y) / 2, j = (x - y) / 2;
	assert(0 <= i && i < N);
	assert(0 <= j && j < M);
	return M * i + j;
}

int getcoord (int nncoord = 0, int nnpair = 0, int offset = 0) {
	return N*M + nncoord * ncoord + nnpair * npair + offset;
}

int getindx (int mn, int x) {
	return mn + x;
}

int getindy (int mn, int y) {
	return mn + y + M - 1;
}

vector<int> getrange (int x, int y) {
	//exclusive
	vector<int> v;
	for (int i = x; i < y; i++) {
		v.push_back(i);
	}
	return v;
}

void construct_network (int nnn, int mmm, int kkk) {
	N = nnn;
	M = mmm;
	K = kkk;
	ncoord = N + M - 1;
	npair = ncoord - K;
	/*
	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);
	*/

	xmin = 0;
	xmax = N + M - 2;
	ymin = -(M - 1);
	ymax = N - 1;
	ytox = _ytox + (M - 1);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			int x = i + j, y = i - j;
			xtoy[x].push_back(y);
			ytox[y].push_back(x);
		}
	}

	//"OR" of the ones w/x-coord = x
	int start1 = N*M, quant1 = ncoord;
	for (int x = xmin; x <= xmax; x++) {
		vector<int> v;
		for (int y : xtoy[x]) {
			v.push_back(getgrid(x, y));
		}
		add_or(v);
	}

	int start2 = start1 + quant1, quant2 = ncoord;
	for (int y = ymin; y <= ymax; y++) {
		vector<int> v;
		for (int x : ytox[y]) {
			v.push_back(getgrid(x, y));
		}
		add_or(v);
	}

	int start3 = start2 + quant2, quant3 = ncoord;
	for (int x = xmin; x <= xmax; x++) {
		vector<int> v;
		for (int y : xtoy[x]) {
			v.push_back(getgrid(x, y));
		}
		add_xor(v);
	}

	int start4 = start3 + quant3, quant4 = ncoord;
	for (int y = ymin; y <= ymax; y++) {
		vector<int> v;
		for (int x : ytox[y]) {
			v.push_back(getgrid(x, y));
		}
		add_xor(v);
	}

	int start5 = start4 + quant4, quant5 = npair;
	for (int x = xmin; x + K <= xmax; x++) {
		add_and({getindx(start1, x), getindx(start1, x + K)});
	}

	int start6 = start5 + quant5, quant6 = npair;
	for (int y = ymin; y + K <= ymax; y++) {
		add_and({getindy(start2, y), getindy(start2, y + K)});
	}

	int start7 = start6 + quant6, quant7 = npair;
	for (int x = xmin; x + K <= xmax; x++) {
		vector<int> v;
		for (int i = 0; i <= K; i++) {
			v.push_back(getindx(start1, x + i));
		}
		add_or(v);
	}

	int start8 = start7 + quant7, quant8 = npair;
	for (int y = ymin; y + K <= ymax; y++) {
		vector<int> v;
		for (int i = 0; i <= K; i++) {
			v.push_back(getindy(start2, y + i));
		}
		add_or(v);
	}

	int start9 = start8 + quant8, quant9 = npair;
	for (int x = xmin; x + K <= xmax; x++) {
		vector<int> v;
		for (int i = 0; i <= K; i++) {
			v.push_back(getindx(start3, x + i));
		}
		add_xor(v);
	}

	int start10 = start9 + quant9, quant10 = npair;
	for (int y = ymin; y + K <= ymax; y++) {
		vector<int> v;
		for (int i = 0; i <= K; i++) {
			v.push_back(getindy(start4, y + i));
		}
		add_xor(v);
	}

	int start11 = start10 + quant10, quant11 = npair;
	for (int x = xmin; x + K <= xmax; x++) {
		add_not(getindx(start9, x));
	}

	int start12 = start11 + quant11, quant12 = npair;
	for (int y = ymin; y + K <= ymax; y++) {
		add_not(getindy(start10, y));
	}
	
	int start13 = start12 + quant12, quant13 = npair;
	for (int x = xmin; x + K <= xmax; x++) {
		add_and({getindx(start7, x), getindx(start11, x)});
	}

	int start14 = start13 + quant13, quant14 = npair;
	for (int y = ymin; y + K <= ymax; y++) {
		add_and({getindy(start8, y), getindy(start12, y)});
	}

	int start15 = start14 + quant14, quant15 = 1;
	add_or(getrange(start13, start14));

	int start16 = start15 + quant15, quant16 = 1;
	add_or(getrange(start14, start15));
	
	int start17 = start16 + quant16, quant17 = 1;
	add_and({start15, start16});

	int start18 = start17 + quant17, quant18 = 1;
	add_or(getrange(start5, start7));

	int start19 = start18 + quant18, quant19 = 1;
	add_and({start17, start18});
}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:191:6: warning: unused variable 'start19' [-Wunused-variable]
  int start19 = start18 + quant18, quant19 = 1;
      ^~~~~~~
vision.cpp:191:35: warning: unused variable 'quant19' [-Wunused-variable]
  int start19 = start18 + quant18, quant19 = 1;
                                   ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 292 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 380 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 292 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 380 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 11 ms 1276 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 6 ms 760 KB Output is correct
42 Correct 5 ms 632 KB Output is correct
43 Correct 9 ms 1112 KB Output is correct
44 Correct 11 ms 1400 KB Output is correct
45 Correct 12 ms 1272 KB Output is correct
46 Correct 10 ms 1144 KB Output is correct
47 Correct 7 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 668 KB Output is correct
2 Correct 7 ms 760 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 7 ms 760 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 7 ms 764 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 4 ms 632 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 7 ms 760 KB Output is correct
18 Correct 7 ms 760 KB Output is correct
19 Correct 6 ms 632 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 636 KB Output is correct
4 Correct 5 ms 636 KB Output is correct
5 Correct 6 ms 756 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 9 ms 888 KB Output is correct
10 Correct 9 ms 1016 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 4 ms 636 KB Output is correct
14 Correct 7 ms 760 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 4 ms 632 KB Output is correct
18 Correct 7 ms 784 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 14 ms 1652 KB Output is correct
21 Correct 21 ms 2296 KB Output is correct
22 Correct 21 ms 2296 KB Output is correct
23 Correct 12 ms 1400 KB Output is correct
24 Correct 15 ms 1652 KB Output is correct
25 Correct 22 ms 2424 KB Output is correct
26 Correct 12 ms 1400 KB Output is correct
27 Correct 23 ms 2804 KB Output is correct
28 Correct 36 ms 3948 KB Output is correct
29 Correct 39 ms 4160 KB Output is correct
30 Correct 34 ms 3704 KB Output is correct
31 Correct 21 ms 2424 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2804 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 6 ms 888 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 13 ms 1652 KB Output is correct
8 Correct 14 ms 1652 KB Output is correct
9 Correct 24 ms 2804 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 292 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 380 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 11 ms 1276 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 6 ms 760 KB Output is correct
42 Correct 5 ms 632 KB Output is correct
43 Correct 9 ms 1112 KB Output is correct
44 Correct 11 ms 1400 KB Output is correct
45 Correct 12 ms 1272 KB Output is correct
46 Correct 10 ms 1144 KB Output is correct
47 Correct 7 ms 888 KB Output is correct
48 Correct 4 ms 668 KB Output is correct
49 Correct 7 ms 760 KB Output is correct
50 Correct 7 ms 760 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 4 ms 632 KB Output is correct
53 Correct 7 ms 760 KB Output is correct
54 Correct 6 ms 760 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 4 ms 632 KB Output is correct
57 Correct 6 ms 760 KB Output is correct
58 Correct 7 ms 764 KB Output is correct
59 Correct 7 ms 760 KB Output is correct
60 Correct 6 ms 760 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 4 ms 632 KB Output is correct
63 Correct 6 ms 760 KB Output is correct
64 Correct 7 ms 760 KB Output is correct
65 Correct 7 ms 760 KB Output is correct
66 Correct 6 ms 632 KB Output is correct
67 Correct 3 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 2 ms 376 KB Output is correct
70 Correct 2 ms 376 KB Output is correct
71 Correct 2 ms 376 KB Output is correct
72 Correct 4 ms 636 KB Output is correct
73 Correct 5 ms 636 KB Output is correct
74 Correct 6 ms 756 KB Output is correct
75 Correct 5 ms 632 KB Output is correct
76 Correct 4 ms 504 KB Output is correct
77 Correct 6 ms 888 KB Output is correct
78 Correct 9 ms 888 KB Output is correct
79 Correct 9 ms 1016 KB Output is correct
80 Correct 8 ms 888 KB Output is correct
81 Correct 5 ms 632 KB Output is correct
82 Correct 4 ms 636 KB Output is correct
83 Correct 7 ms 760 KB Output is correct
84 Correct 6 ms 760 KB Output is correct
85 Correct 3 ms 376 KB Output is correct
86 Correct 4 ms 632 KB Output is correct
87 Correct 7 ms 784 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 14 ms 1652 KB Output is correct
90 Correct 21 ms 2296 KB Output is correct
91 Correct 21 ms 2296 KB Output is correct
92 Correct 12 ms 1400 KB Output is correct
93 Correct 15 ms 1652 KB Output is correct
94 Correct 22 ms 2424 KB Output is correct
95 Correct 12 ms 1400 KB Output is correct
96 Correct 23 ms 2804 KB Output is correct
97 Correct 36 ms 3948 KB Output is correct
98 Correct 39 ms 4160 KB Output is correct
99 Correct 34 ms 3704 KB Output is correct
100 Correct 21 ms 2424 KB Output is correct
101 Correct 2 ms 376 KB Output is correct
102 Correct 2 ms 376 KB Output is correct
103 Correct 24 ms 2804 KB Output is correct
104 Correct 2 ms 376 KB Output is correct
105 Correct 4 ms 632 KB Output is correct
106 Correct 6 ms 888 KB Output is correct
107 Correct 4 ms 632 KB Output is correct
108 Correct 4 ms 632 KB Output is correct
109 Correct 13 ms 1652 KB Output is correct
110 Correct 14 ms 1652 KB Output is correct
111 Correct 24 ms 2804 KB Output is correct
112 Correct 2 ms 376 KB Output is correct
113 Correct 2 ms 376 KB Output is correct
114 Correct 36 ms 3800 KB Output is correct
115 Correct 3 ms 376 KB Output is correct
116 Correct 4 ms 636 KB Output is correct
117 Correct 17 ms 1912 KB Output is correct
118 Correct 19 ms 2152 KB Output is correct
119 Correct 39 ms 4088 KB Output is correct
120 Correct 38 ms 4088 KB Output is correct
121 Correct 39 ms 4088 KB Output is correct
122 Correct 39 ms 4344 KB Output is correct
123 Correct 24 ms 2804 KB Output is correct
124 Correct 36 ms 3928 KB Output is correct
125 Correct 39 ms 4216 KB Output is correct
126 Correct 39 ms 4216 KB Output is correct
127 Correct 35 ms 3704 KB Output is correct
128 Correct 22 ms 2424 KB Output is correct