Submission #246790

# Submission time Handle Problem Language Result Execution time Memory
246790 2020-07-10T08:14:50 Z Evirir Vision Program (IOI19_vision) C++17
100 / 100
43 ms 4156 KB
#include "vision.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<x<<endl
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_by_key
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void SD(int t=0){ cout<<"TEST "<<t<<endl; }

const int MAXN = 405;
const int MOD = 1e9+7;
bool DEBUG=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);
*/

int dist(ii a, ii b)
{
	return abs(a.F-b.F)+abs(a.S-b.S);
}

vi v;
int off;

vector<int> d1[MAXN],d2[MAXN];
int t1[2],t2[2];

void construct_network(int n, int m, int K)
{
	if(n*m==2){
		add_or({0,1});
		return;
	}
	
	off=m-1;
	vi all;
	
	for(int i=0;i<n;i++) for(int j=0;j<m;j++)
	{
		all.pb(i*m+j);
		d1[i+j].pb(i*m+j);
		d2[i-j+off].pb(i*m+j);
	}
	
	//create dummy 0 and 1
	int zero = add_and(all);
	int one = add_or(all);
	
	forn(i,0,m+n-1)
	{
		int tmp=add_or(d1[i]);
		if(i==0) t1[0]=tmp;
		if(i==m+n-2) t1[1]=tmp;
	}
	forn(i,0,m+n-1)
	{
		int tmp=add_or(d2[i]);
		if(i==0) t2[0]=tmp;
		if(i==m+n-2) t2[1]=tmp;
	}
	
	vi exact,test;
	
	//----------------------------------------------
	//d1 K, d2 large
	for(int i=t1[0];i+K<=t1[1];i++)
	{
		v={i,i+K};
		exact.pb(add_and(v)); if(DEBUG) cout<<"exact: "<<exact.back()<<endl;
	}
	for(int i=t2[0];i+K+1<=t2[1];i++)
	{
		v.clear();
		for(int j=i+K+1;j<=t2[1];j++) v.pb(j);
		test.pb(add_and({i,add_or(v)})); if(DEBUG) cout<<"test: "<<test.back()<<endl;
	}
	
	int f1,f2;
	int final1, final2;
	
	if(DEBUG){
		cout<<"exact.size()="<<exact.size()<<endl;
		cout<<"test.size()="<<test.size()<<endl;
	}
	
	f1 = (exact.size() ? add_or(exact) : zero);
	f2 = (test.size() ? add_not(add_or(test)) : one);
	
	v = {f1,f2}; if(DEBUG){ watch(f1); watch(f2); }
	final1=add_and(v);
	//phase 1 end
	//----------------------------------------------
	
	exact.clear(); test.clear(); v.clear();
	
	//----------------------------------------------
	//d2 exact, d1 large
	for(int i=t2[0];i+K<=t2[1];i++)
	{
		v={i,i+K};
		exact.pb(add_and(v)); if(DEBUG) cout<<"exact: "<<exact.back()<<endl;
	}
	for(int i=t1[0];i+K+1<=t1[1];i++)
	{
		v.clear();
		for(int j=i+K+1;j<=t1[1];j++) v.pb(j);
		test.pb(add_and({i,add_or(v)})); if(DEBUG) cout<<"test: "<<test.back()<<endl;
	}
	
	f1 = (exact.size() ? add_or(exact) : zero);
	f2 = (test.size() ? add_not(add_or(test)) : one);
	
	v = {f1,f2}; if(DEBUG){ watch(f1); watch(f2); }
	final2=add_and(v);
	//phase 2 end
	//----------------------------------------------
	
	//----------------------------------------------
	//check one of them is correct
	v = {final1, final2};
	add_or(v);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 12 ms 1152 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 10 ms 896 KB Output is correct
42 Correct 7 ms 640 KB Output is correct
43 Correct 14 ms 1408 KB Output is correct
44 Correct 12 ms 1152 KB Output is correct
45 Correct 11 ms 1024 KB Output is correct
46 Correct 10 ms 896 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 768 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 9 ms 768 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 9 ms 768 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 436 KB Output is correct
15 Correct 9 ms 768 KB Output is correct
16 Correct 8 ms 640 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 17 ms 1024 KB Output is correct
9 Correct 14 ms 896 KB Output is correct
10 Correct 9 ms 768 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 7 ms 640 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 8 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 22 ms 2352 KB Output is correct
21 Correct 20 ms 1840 KB Output is correct
22 Correct 15 ms 1456 KB Output is correct
23 Correct 13 ms 1456 KB Output is correct
24 Correct 23 ms 2352 KB Output is correct
25 Correct 16 ms 1712 KB Output is correct
26 Correct 14 ms 1456 KB Output is correct
27 Correct 40 ms 4152 KB Output is correct
28 Correct 32 ms 3376 KB Output is correct
29 Correct 28 ms 2868 KB Output is correct
30 Correct 24 ms 2620 KB Output is correct
31 Correct 22 ms 2364 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 4156 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
4 Correct 11 ms 1024 KB Output is correct
5 Correct 10 ms 768 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 22 ms 2352 KB Output is correct
8 Correct 23 ms 2352 KB Output is correct
9 Correct 43 ms 4148 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 12 ms 1152 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 10 ms 896 KB Output is correct
42 Correct 7 ms 640 KB Output is correct
43 Correct 14 ms 1408 KB Output is correct
44 Correct 12 ms 1152 KB Output is correct
45 Correct 11 ms 1024 KB Output is correct
46 Correct 10 ms 896 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
48 Correct 9 ms 768 KB Output is correct
49 Correct 6 ms 512 KB Output is correct
50 Correct 6 ms 512 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 9 ms 768 KB Output is correct
53 Correct 7 ms 640 KB Output is correct
54 Correct 6 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 9 ms 768 KB Output is correct
57 Correct 8 ms 640 KB Output is correct
58 Correct 6 ms 512 KB Output is correct
59 Correct 6 ms 512 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 436 KB Output is correct
62 Correct 9 ms 768 KB Output is correct
63 Correct 8 ms 640 KB Output is correct
64 Correct 6 ms 512 KB Output is correct
65 Correct 6 ms 512 KB Output is correct
66 Correct 5 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 5 ms 384 KB Output is correct
69 Correct 4 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 8 ms 768 KB Output is correct
73 Correct 7 ms 640 KB Output is correct
74 Correct 7 ms 512 KB Output is correct
75 Correct 7 ms 512 KB Output is correct
76 Correct 6 ms 512 KB Output is correct
77 Correct 17 ms 1024 KB Output is correct
78 Correct 14 ms 896 KB Output is correct
79 Correct 9 ms 768 KB Output is correct
80 Correct 8 ms 640 KB Output is correct
81 Correct 8 ms 640 KB Output is correct
82 Correct 9 ms 768 KB Output is correct
83 Correct 7 ms 640 KB Output is correct
84 Correct 6 ms 512 KB Output is correct
85 Correct 5 ms 384 KB Output is correct
86 Correct 9 ms 768 KB Output is correct
87 Correct 8 ms 512 KB Output is correct
88 Correct 5 ms 384 KB Output is correct
89 Correct 22 ms 2352 KB Output is correct
90 Correct 20 ms 1840 KB Output is correct
91 Correct 15 ms 1456 KB Output is correct
92 Correct 13 ms 1456 KB Output is correct
93 Correct 23 ms 2352 KB Output is correct
94 Correct 16 ms 1712 KB Output is correct
95 Correct 14 ms 1456 KB Output is correct
96 Correct 40 ms 4152 KB Output is correct
97 Correct 32 ms 3376 KB Output is correct
98 Correct 28 ms 2868 KB Output is correct
99 Correct 24 ms 2620 KB Output is correct
100 Correct 22 ms 2364 KB Output is correct
101 Correct 4 ms 384 KB Output is correct
102 Correct 5 ms 384 KB Output is correct
103 Correct 39 ms 4156 KB Output is correct
104 Correct 5 ms 384 KB Output is correct
105 Correct 8 ms 768 KB Output is correct
106 Correct 11 ms 1024 KB Output is correct
107 Correct 10 ms 768 KB Output is correct
108 Correct 9 ms 768 KB Output is correct
109 Correct 22 ms 2352 KB Output is correct
110 Correct 23 ms 2352 KB Output is correct
111 Correct 43 ms 4148 KB Output is correct
112 Correct 5 ms 384 KB Output is correct
113 Correct 5 ms 384 KB Output is correct
114 Correct 32 ms 3508 KB Output is correct
115 Correct 5 ms 384 KB Output is correct
116 Correct 9 ms 768 KB Output is correct
117 Correct 14 ms 1456 KB Output is correct
118 Correct 21 ms 2096 KB Output is correct
119 Correct 26 ms 2884 KB Output is correct
120 Correct 26 ms 2884 KB Output is correct
121 Correct 26 ms 2884 KB Output is correct
122 Correct 26 ms 2884 KB Output is correct
123 Correct 39 ms 4148 KB Output is correct
124 Correct 31 ms 3508 KB Output is correct
125 Correct 26 ms 2868 KB Output is correct
126 Correct 27 ms 2868 KB Output is correct
127 Correct 24 ms 2620 KB Output is correct
128 Correct 21 ms 2484 KB Output is correct