Submission #293191

# Submission time Handle Problem Language Result Execution time Memory
293191 2020-09-07T18:07:10 Z AlanChen Vision Program (IOI19_vision) C++14
100 / 100
25 ms 2116 KB
#include "vision.h"


#include <bits/stdc++.h>
using namespace std;

template<class A> using v=vector<A>;
template<class A,class B=A> using p=pair<A,B>;

typedef v<int> vi;
typedef p<int> pi;
typedef string str;

#define f first
#define s second
#define mp make_pair
#define ins insert
#define pb push_back
#define sz(S) (int)S.size()


#define get4(a,b,c,d,...) d

#define lp3(x,a,b) for(int x=(a);x<(b);x++)
#define lp2(x,a) lp3(x,0,a)
#define lp1(a) lp2(loopvar,a)
#define lp(x...) get4(x,lp3,lp2,lp1,0)(x)

#define trv(x,S) for(auto& x:(S))


int c0,c1;
struct num
{
	int x[9];
	num()
	{
		lp(i,9) x[i]=c0;
	}
};
num addnum(num n1,num n2)
{
	num ans;
	int carry=add_and({{n1.x[0],n2.x[0]}});
	ans.x[0]=add_xor({n1.x[0],n2.x[0]});
	lp(i,1,9){
		ans.x[i]=add_xor({carry,n1.x[i],n2.x[i]});
		if(i<8) carry=add_or({
			add_and({n1.x[i],n2.x[i]}),
					add_and({carry,n2.x[i]}),
					add_and({n1.x[i],carry})
		});
	}
	return ans;
}
num cplm(num n1)
{
	num ans;
	lp(i,9) ans.x[i]=add_not(n1.x[i]);

	num n2;
	n2.x[0]=c1;

	return addnum(ans,n2);
}

int n,m,tgt;
int orig[500][500];
int prj[2][500];
int disthelp[2][500][500];
int dist[2][500];
int isx[2][500];
int dim[2];




void construct_network(int H, int W, int Tgt)
{
	n=H,m=W,tgt=Tgt;


	{
		vi Ns;
		lp(i,n*m) {
			Ns.pb(i);
		}
		c1=add_or(Ns);
		c0=add_not(c1);
	}

	lp(i,n) lp(j,m) orig[i][j]=i*m+j;

	lp(i,n)
	{
		vi Ns;
		lp(j,m) Ns.pb(orig[i][j]);
		prj[0][i]=add_or(Ns);
	}
	lp(j,m)
	{
		vi Ns;
		lp(i,n) Ns.pb(orig[i][j]);
		prj[1][j]=add_or(Ns);
	}
	dim[0]=n,dim[1]=m;


	num fds[2];
	lp(d,2)
	{
		int iss;
		{
			vi Ns;
			lp(i,dim[d]) Ns.pb(prj[d][i]);
			iss=add_xor(Ns);
		}
		int isn=add_not(iss);


		int issamebit[8];
		int consenbit[8];
		lp(i,8)
		{
			vi Ns; Ns.pb(c0);
			lp(j,dim[d]) if(bitset<9>(j)[i]) Ns.pb(prj[d][j]);
			issamebit[i]=add_not(add_xor(Ns));
			consenbit[i]=add_or(Ns);
		}
		num possnums[9][2];
		lp(numsame,9)
		{
			lp(i,numsame) lp(j,2) possnums[numsame][j].x[i]=consenbit[i];
			lp(i,numsame,8) lp(j,2){
				vi Ns; Ns.pb(c0);
				lp(alln,dim[d]) if(bitset<9>(alln)[numsame]==j&&bitset<9>(alln)[i]) Ns.pb(prj[d][alln]);
				possnums[numsame][j].x[i]=add_or(Ns);
			}
		}
		num curr[2];
		lp(j,2) curr[j]=possnums[0][j];

		lp(i,1,8) issamebit[i]=add_and({issamebit[i-1],issamebit[i]});

		lp(j,2) lp(ns,1,9) lp(bt,8){
			curr[j].x[bt]=add_or({
				add_and({issamebit[ns-1],possnums[ns][j].x[bt]}),
						add_and({add_not(issamebit[ns-1]),curr[j].x[bt]})
			});
		}
		num diff=addnum(curr[0],cplm(curr[1]));
		num diff2=cplm(diff);
		num fd;
		lp(bt,9) fd.x[bt]=add_or({
			add_and({diff2.x[8],diff.x[bt]}),
					add_and({diff.x[8],diff2.x[bt]})
		});
		lp(bt,9) fd.x[bt]=add_and({isn,fd.x[bt]});
		fds[d]=fd;

	}
	num ttl=addnum(fds[0],fds[1]);

	vi ansarr;

	lp(i,9)
	{
		if(bitset<9>(tgt)[i]) ansarr.pb(ttl.x[i]);
		else ansarr.pb(add_not(ttl.x[i]));
	}

	add_and(ansarr);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 7 ms 1024 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 4 ms 768 KB Output is correct
42 Correct 4 ms 768 KB Output is correct
43 Correct 8 ms 1024 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 5 ms 1024 KB Output is correct
46 Correct 5 ms 1024 KB Output is correct
47 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 896 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 9 ms 1456 KB Output is correct
21 Correct 10 ms 1456 KB Output is correct
22 Correct 10 ms 1456 KB Output is correct
23 Correct 10 ms 1584 KB Output is correct
24 Correct 10 ms 1360 KB Output is correct
25 Correct 9 ms 1328 KB Output is correct
26 Correct 9 ms 1328 KB Output is correct
27 Correct 17 ms 2108 KB Output is correct
28 Correct 17 ms 2108 KB Output is correct
29 Correct 17 ms 2108 KB Output is correct
30 Correct 17 ms 2108 KB Output is correct
31 Correct 17 ms 2108 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2108 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 10 ms 1456 KB Output is correct
8 Correct 9 ms 1328 KB Output is correct
9 Correct 17 ms 2100 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 7 ms 1024 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 4 ms 768 KB Output is correct
42 Correct 4 ms 768 KB Output is correct
43 Correct 8 ms 1024 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 5 ms 1024 KB Output is correct
46 Correct 5 ms 1024 KB Output is correct
47 Correct 5 ms 1024 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 2 ms 896 KB Output is correct
53 Correct 2 ms 896 KB Output is correct
54 Correct 2 ms 896 KB Output is correct
55 Correct 2 ms 896 KB Output is correct
56 Correct 2 ms 512 KB Output is correct
57 Correct 2 ms 512 KB Output is correct
58 Correct 2 ms 512 KB Output is correct
59 Correct 2 ms 512 KB Output is correct
60 Correct 2 ms 512 KB Output is correct
61 Correct 2 ms 512 KB Output is correct
62 Correct 2 ms 896 KB Output is correct
63 Correct 2 ms 896 KB Output is correct
64 Correct 2 ms 896 KB Output is correct
65 Correct 2 ms 896 KB Output is correct
66 Correct 2 ms 896 KB Output is correct
67 Correct 2 ms 896 KB Output is correct
68 Correct 1 ms 512 KB Output is correct
69 Correct 1 ms 512 KB Output is correct
70 Correct 1 ms 512 KB Output is correct
71 Correct 1 ms 512 KB Output is correct
72 Correct 3 ms 768 KB Output is correct
73 Correct 3 ms 768 KB Output is correct
74 Correct 3 ms 768 KB Output is correct
75 Correct 3 ms 768 KB Output is correct
76 Correct 3 ms 768 KB Output is correct
77 Correct 4 ms 768 KB Output is correct
78 Correct 4 ms 768 KB Output is correct
79 Correct 6 ms 768 KB Output is correct
80 Correct 4 ms 768 KB Output is correct
81 Correct 4 ms 768 KB Output is correct
82 Correct 2 ms 512 KB Output is correct
83 Correct 3 ms 512 KB Output is correct
84 Correct 2 ms 512 KB Output is correct
85 Correct 2 ms 512 KB Output is correct
86 Correct 2 ms 896 KB Output is correct
87 Correct 2 ms 896 KB Output is correct
88 Correct 2 ms 896 KB Output is correct
89 Correct 9 ms 1456 KB Output is correct
90 Correct 10 ms 1456 KB Output is correct
91 Correct 10 ms 1456 KB Output is correct
92 Correct 10 ms 1584 KB Output is correct
93 Correct 10 ms 1360 KB Output is correct
94 Correct 9 ms 1328 KB Output is correct
95 Correct 9 ms 1328 KB Output is correct
96 Correct 17 ms 2108 KB Output is correct
97 Correct 17 ms 2108 KB Output is correct
98 Correct 17 ms 2108 KB Output is correct
99 Correct 17 ms 2108 KB Output is correct
100 Correct 17 ms 2108 KB Output is correct
101 Correct 1 ms 512 KB Output is correct
102 Correct 2 ms 512 KB Output is correct
103 Correct 17 ms 2108 KB Output is correct
104 Correct 1 ms 512 KB Output is correct
105 Correct 4 ms 768 KB Output is correct
106 Correct 4 ms 768 KB Output is correct
107 Correct 2 ms 512 KB Output is correct
108 Correct 2 ms 896 KB Output is correct
109 Correct 10 ms 1456 KB Output is correct
110 Correct 9 ms 1328 KB Output is correct
111 Correct 17 ms 2100 KB Output is correct
112 Correct 1 ms 512 KB Output is correct
113 Correct 1 ms 512 KB Output is correct
114 Correct 17 ms 2108 KB Output is correct
115 Correct 2 ms 512 KB Output is correct
116 Correct 2 ms 896 KB Output is correct
117 Correct 10 ms 1584 KB Output is correct
118 Correct 9 ms 1328 KB Output is correct
119 Correct 17 ms 2104 KB Output is correct
120 Correct 17 ms 2116 KB Output is correct
121 Correct 17 ms 2116 KB Output is correct
122 Correct 25 ms 2116 KB Output is correct
123 Correct 17 ms 2108 KB Output is correct
124 Correct 17 ms 2108 KB Output is correct
125 Correct 17 ms 2108 KB Output is correct
126 Correct 17 ms 2108 KB Output is correct
127 Correct 17 ms 2108 KB Output is correct
128 Correct 17 ms 2108 KB Output is correct