Submission #643844

# Submission time Handle Problem Language Result Execution time Memory
643844 2022-09-23T05:46:12 Z ymm Vision Program (IOI19_vision) C++17
100 / 100
11 ms 1508 KB
#include "vision.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 40'010;
int h, w, k;
int n;
int nxt;
const int BITS = 9;

int get_n(int x, int y) { return 0 <= x && x < h && 0 <= y && y < w? x*w + y: -1;}

void ha(int a, int b, int &x, int &y)
{
	// a^b  a&b
	add_xor({a, b});
	add_and({a, b});
	x = nxt;
	y = nxt+1;
	nxt += 2;
}
void fa(int a, int b, int c, int &x, int &y)
{
	// a^b  a^b^c  a&b  (a^b)&c  (a&b)|((a^b)&c)
	add_xor({a, b});
	add_xor({nxt, c});
	add_and({a, b});
	add_and({nxt, c});
	add_or({nxt+2, nxt+3});
	x = nxt+1;
	y = nxt+4;
	nxt += 5;
}
void byte_add(int a[], int b[], int x[], int bits = BITS)
{
	int c[BITS];
	ha(a[0], b[0], x[0], c[0]);
	Loop (i,1,bits)
		fa(a[i], b[i], c[i-1], x[i], c[i]);
}
void byte_write(int val, int x[])
{
	Loop (i,0,BITS) {
		add_xor({n+(val&1)});
		x[i] = nxt++;
		val >>= 1;
	}
}
void byte_cmp(int a[], int b[], int &x)
{
	Loop (i,0,BITS)
		add_xor({a[i], b[i]});
	vector<int> vec;
	Loop (i,0,BITS)
		vec.push_back(nxt+i);
	add_or(vec);
	add_not(nxt+BITS);
	x = nxt+BITS+1;
	nxt += BITS+2;
}

void construct_network(int H, int W, int K)
{
	h = H; w = W; k = K;
	n = w*h;
	add_xor({0,0});
	add_not(n);
	nxt = n+2;
	int A[BITS], B[BITS];
	int dis[BITS], goal[BITS];
	Loop (dir,0,2) {
		int kooft = nxt;
		int lst = n;
		Loop (j,0,dir?h:w) {
			vector<int> vec;
			vec.push_back(lst);
			Loop (i,0,dir?w:h)
				vec.push_back(get_n(dir?j:i, dir?i:j));
			add_xor(vec);
			lst=nxt++;
		}
		int nums[1<<BITS][BITS], len=dir?h:w;
		Loop (j,0,len) {
			Loop (k,0,BITS)
				nums[j][k] = n;
			nums[j][0] = kooft+j;
		}
		for (int i = 0; len > 1; ++i) {
			for (int j = 0; j < len; j += 2) {
				if (j+1 < len)
					byte_add(nums[j], nums[j+1], nums[j/2], i+2);
				else
					memcpy(nums[j/2], nums[j], sizeof(nums[j]));
			}
			len = (len+1)/2;
		}
		memcpy(dir?B:A, nums[0], sizeof(nums[0]));
	}
	byte_add(A, B, dis);
	byte_write(k, goal);
	int ans;
	byte_cmp(dis, goal, ans);
	//printf("a = %d\nb = %d\nsum = %d\nk = %d\n", n+2, n+11, dis, goal);
}
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 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 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 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 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 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 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 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
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 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 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 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 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 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 4 ms 724 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 4 ms 712 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 4 ms 584 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 9 ms 968 KB Output is correct
21 Correct 6 ms 936 KB Output is correct
22 Correct 6 ms 980 KB Output is correct
23 Correct 8 ms 980 KB Output is correct
24 Correct 6 ms 936 KB Output is correct
25 Correct 6 ms 980 KB Output is correct
26 Correct 6 ms 980 KB Output is correct
27 Correct 11 ms 1488 KB Output is correct
28 Correct 10 ms 1488 KB Output is correct
29 Correct 10 ms 1444 KB Output is correct
30 Correct 10 ms 1488 KB Output is correct
31 Correct 10 ms 1496 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1488 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 6 ms 980 KB Output is correct
8 Correct 6 ms 940 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 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 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 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 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 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 4 ms 724 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 4 ms 712 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 5 ms 724 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 3 ms 564 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 468 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 2 ms 468 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 2 ms 468 KB Output is correct
68 Correct 1 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 1 ms 212 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 2 ms 468 KB Output is correct
74 Correct 2 ms 468 KB Output is correct
75 Correct 2 ms 468 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 3 ms 596 KB Output is correct
78 Correct 3 ms 596 KB Output is correct
79 Correct 3 ms 596 KB Output is correct
80 Correct 4 ms 584 KB Output is correct
81 Correct 3 ms 596 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 2 ms 468 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 3 ms 468 KB Output is correct
87 Correct 2 ms 468 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 9 ms 968 KB Output is correct
90 Correct 6 ms 936 KB Output is correct
91 Correct 6 ms 980 KB Output is correct
92 Correct 8 ms 980 KB Output is correct
93 Correct 6 ms 936 KB Output is correct
94 Correct 6 ms 980 KB Output is correct
95 Correct 6 ms 980 KB Output is correct
96 Correct 11 ms 1488 KB Output is correct
97 Correct 10 ms 1488 KB Output is correct
98 Correct 10 ms 1444 KB Output is correct
99 Correct 10 ms 1488 KB Output is correct
100 Correct 10 ms 1496 KB Output is correct
101 Correct 1 ms 212 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Correct 11 ms 1488 KB Output is correct
104 Correct 0 ms 212 KB Output is correct
105 Correct 2 ms 468 KB Output is correct
106 Correct 3 ms 596 KB Output is correct
107 Correct 2 ms 468 KB Output is correct
108 Correct 2 ms 556 KB Output is correct
109 Correct 6 ms 980 KB Output is correct
110 Correct 6 ms 940 KB Output is correct
111 Correct 10 ms 1488 KB Output is correct
112 Correct 1 ms 304 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 11 ms 1508 KB Output is correct
115 Correct 2 ms 468 KB Output is correct
116 Correct 2 ms 500 KB Output is correct
117 Correct 6 ms 980 KB Output is correct
118 Correct 6 ms 952 KB Output is correct
119 Correct 10 ms 1464 KB Output is correct
120 Correct 11 ms 1480 KB Output is correct
121 Correct 11 ms 1488 KB Output is correct
122 Correct 11 ms 1448 KB Output is correct
123 Correct 10 ms 1452 KB Output is correct
124 Correct 10 ms 1488 KB Output is correct
125 Correct 10 ms 1488 KB Output is correct
126 Correct 10 ms 1460 KB Output is correct
127 Correct 10 ms 1488 KB Output is correct
128 Correct 10 ms 1472 KB Output is correct