답안 #250082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250082 2020-07-16T20:25:41 Z crackersamdjam Vision Program (IOI19_vision) C++14
100 / 100
35 ms 2176 KB
#ifndef CLION
#ifndef ONLINE_JUDGE
#define ONLINE_JUDGE
#endif
#endif

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

#ifndef ONLINE_JUDGE
template<typename T>
void print(T a){std::cout<<a<<std::endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {std::cout<<a<<' ',print(args...);}
#else
#include "vision.h"
template<typename... Args>
void print(Args... args){}
#endif

#ifndef ONLINE_JUDGE
int LIM =  10000;
vector<int> all;
int eval(int i){
	return all[i];
}
int add_and(std::vector<int> Ns){
	assert(all.size() < LIM);
	assert(Ns.size());
	int ret = 1;
	for(int i: Ns){
		assert(i >= 0 and i < all.size());
		ret &= all[i];
	}
	if(Ns.empty())
		ret = 0;
	all.emplace_back(ret);
	return all.size()-1;
}
int add_or(std::vector<int> Ns){
	assert(all.size() < LIM);
	assert(Ns.size());
	int ret = 0;
	for(int i: Ns){
		assert(i >= 0 and i < all.size());
		ret |= all[i];
	}
	all.emplace_back(ret);
	return all.size()-1;
}
int add_xor(std::vector<int> Ns){
	assert(all.size() < LIM);
	assert(Ns.size());
	int ret = 0;
	for(int i: Ns){
		assert(i >= 0 and i < all.size());
		ret ^= all[i];
	}
	all.emplace_back(ret);
	return all.size()-1;
}
int add_not(int N){
	assert(all.size() < LIM);
	assert(N >= 0 and N < all.size());
	all.emplace_back(!all[N]);
	return all.size()-1;
}
#else
int eval(int i){
	return 0;
}
#endif

const int MM = 600;

int n, m, mx, zero;
int prea[MM], pre2a[MM], sufa[MM], suf2a[MM];
int *pre = prea+1, *pre2 = pre2a+1, *suf = sufa+1, *suf2 = suf2a+1;

bool ok(int i, int j){ return i >= 0 and i < n and j >= 0 and j < m; }
int at(int i, int j){ return i*m+j; }

int go(int k){
	//if dist >= k
	vector<int> ret = {zero};
	print("**********");
	print("try", k);
	
	for(int i = -1; i <= mx; i++){
		if(!suf[i+k])
			break;
		ret.push_back(add_and({pre[i], suf[i+k]}));
		//both are 1 means that points are >= k apart
		print("or", i, i+k, eval(ret.back()));
	}
	
	for(int i = -1; i <= mx; i++){
		if(!suf2[i+k])
			break;
		ret.push_back(add_and({pre2[i], suf2[i+k]}));
		print("or2", i, i+k, eval(ret.back()));
	}
	
	//returns if outside
	return add_or(ret);
}

void construct_network(int _n, int _m, int k){
	n = _n, m = _m;
	if(n*m == 2){
		//edge case where I can not get "zero"
		if(k == 1){
			add_or({0, 1});
			return; //[2] is 1
		}
		
		add_not(1); //[2] is 0
		return;
	}
	
	zero = add_and({0, 1, 2}); //must be 0
	
	mx = n+m+5;
	
	pre[-1] = zero;
	suf[mx+1] = zero;
	
	for(int i = 0; i <= mx; i++){
		vector<int> v = {pre[i-1]};
		print("in", i);
		for(int j = 0; j <= n+m; j++){
			if(ok(j, i-j)){
				print(j, i-j, "-", eval(at(j, i-j)));
				v.push_back(at(j, i-j));
			}
		}
		pre[i] = add_or(v);
		print("pre ", eval(pre[i]));
	}
	
	for(int i = mx; i >= 0; i--){
		vector<int> v = {suf[i+1]};
		print("in", i);
		for(int j = 0; j <= n+m; j++){
			if(ok(j, i-j)){
				print(j, i-j, "-", eval(at(j, i-j)));
				v.push_back(at(j, i-j));
			}
		}
		suf[i] = add_or(v);
		print("suf ", eval(suf[i]));
	}
	
	pre2[-1] = zero;
	suf2[mx+1] = zero;
	
	for(int i = 0; i <= mx; i++){
		vector<int> v = {pre2[i-1]};
		print("in2", i);
		for(int j = 0; j <= n+m; j++){
			if(ok(j, m-1-i+j)){
				print(j, m-1-i+j, "-", eval(at(j, m-1-i+j)));
				v.push_back(at(j, m-1-i+j));
			}
		}
		pre2[i] = add_or(v);
		print("pre ", eval(pre2[i]));
	}
	for(int i = mx; i >= 0; i--){
		vector<int> v = {suf2[i+1]};
		print("in2", i);
		for(int j = 0; j <= n+m; j++){
			if(ok(j, m-1-i+j)){
				print(j, m-1-i+j, "-", eval(at(j, m-1-i+j)));
				v.push_back(at(j, m-1-i+j));
			}
		}
		suf2[i] = add_or(v);
		print("suf ", eval(suf2[i]));
	}
	
	int hi = go(k+1); // if k+1 (does not) work
	int lo = go(k); // if k works
	
	int ret = add_and({add_not(hi), lo});
	print("ans", eval(hi), eval(lo), eval(ret));
}

#ifndef ONLINE_JUDGE
//int main(){
//	all = {0, 0, 0, 0, 1, 0, 0, 0, 1};
//	construct_network(3, 3, 2);
//	cout<<all.back()<<endl;
//}

mt19937 g;
int randint(int l, int r){ return uniform_int_distribution<int>(l, r)(g); }
int main(int argc, char *args[]){
//	freopen("../in", "w", stdout);
	int sd = argc > 1 ? atoi(args[1]) : 0;

//	sd = 2;

	g = mt19937(sd);
	int N = randint(1, 3), M = randint(1, 3);
	if(N+M == 2)
		M++;
	int K = randint(1, N+M-2);

	all.resize(N*M);

	int AX = randint(0, N-1), AY = randint(0, M-1);
	int BX, BY;
	do{
		BX = randint(0, N-1), BY = randint(0, M-1);
	} while(BX == AX and BY == AY);

	all[AX*M+AY] = all[BX*M+BY] = 1;

	cout<<N<<' '<<M<<' '<<K<<endl;
	cout<<AX<<' '<<AY<<endl;
	cout<<BX<<' '<<BY<<endl;
	cout<<"Reeeeee "<<AX*M+AY<<' '<<BX*M+BY<<endl;

	int DIST = abs(AX-BX) + abs(AY-BY);
	int ANS = DIST==K;
	construct_network(N, M, K);
	cout<<all.back()<<' '<<ANS<<endl;
	assert(all.back() == ANS);
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 6 ms 768 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 4 ms 640 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 6 ms 768 KB Output is correct
44 Correct 6 ms 768 KB Output is correct
45 Correct 6 ms 768 KB Output is correct
46 Correct 6 ms 768 KB Output is correct
47 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 11 ms 1280 KB Output is correct
21 Correct 10 ms 1280 KB Output is correct
22 Correct 11 ms 1152 KB Output is correct
23 Correct 10 ms 1152 KB Output is correct
24 Correct 11 ms 1280 KB Output is correct
25 Correct 11 ms 1280 KB Output is correct
26 Correct 10 ms 1152 KB Output is correct
27 Correct 20 ms 2176 KB Output is correct
28 Correct 19 ms 2176 KB Output is correct
29 Correct 19 ms 2176 KB Output is correct
30 Correct 19 ms 2048 KB Output is correct
31 Correct 18 ms 1920 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2176 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 11 ms 1280 KB Output is correct
8 Correct 11 ms 1280 KB Output is correct
9 Correct 19 ms 2176 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 6 ms 768 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 4 ms 640 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 6 ms 768 KB Output is correct
44 Correct 6 ms 768 KB Output is correct
45 Correct 6 ms 768 KB Output is correct
46 Correct 6 ms 768 KB Output is correct
47 Correct 6 ms 768 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 2 ms 512 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 2 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 2 ms 512 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 0 ms 256 KB Output is correct
69 Correct 0 ms 256 KB Output is correct
70 Correct 0 ms 256 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 2 ms 512 KB Output is correct
73 Correct 3 ms 512 KB Output is correct
74 Correct 3 ms 512 KB Output is correct
75 Correct 2 ms 512 KB Output is correct
76 Correct 2 ms 512 KB Output is correct
77 Correct 4 ms 640 KB Output is correct
78 Correct 4 ms 640 KB Output is correct
79 Correct 4 ms 640 KB Output is correct
80 Correct 4 ms 640 KB Output is correct
81 Correct 4 ms 512 KB Output is correct
82 Correct 2 ms 512 KB Output is correct
83 Correct 2 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 1 ms 384 KB Output is correct
86 Correct 2 ms 512 KB Output is correct
87 Correct 1 ms 384 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 11 ms 1280 KB Output is correct
90 Correct 10 ms 1280 KB Output is correct
91 Correct 11 ms 1152 KB Output is correct
92 Correct 10 ms 1152 KB Output is correct
93 Correct 11 ms 1280 KB Output is correct
94 Correct 11 ms 1280 KB Output is correct
95 Correct 10 ms 1152 KB Output is correct
96 Correct 20 ms 2176 KB Output is correct
97 Correct 19 ms 2176 KB Output is correct
98 Correct 19 ms 2176 KB Output is correct
99 Correct 19 ms 2048 KB Output is correct
100 Correct 18 ms 1920 KB Output is correct
101 Correct 0 ms 256 KB Output is correct
102 Correct 0 ms 256 KB Output is correct
103 Correct 20 ms 2176 KB Output is correct
104 Correct 0 ms 384 KB Output is correct
105 Correct 3 ms 512 KB Output is correct
106 Correct 4 ms 640 KB Output is correct
107 Correct 2 ms 512 KB Output is correct
108 Correct 2 ms 512 KB Output is correct
109 Correct 11 ms 1280 KB Output is correct
110 Correct 11 ms 1280 KB Output is correct
111 Correct 19 ms 2176 KB Output is correct
112 Correct 0 ms 256 KB Output is correct
113 Correct 0 ms 256 KB Output is correct
114 Correct 20 ms 2176 KB Output is correct
115 Correct 2 ms 384 KB Output is correct
116 Correct 2 ms 512 KB Output is correct
117 Correct 10 ms 1152 KB Output is correct
118 Correct 10 ms 1280 KB Output is correct
119 Correct 30 ms 2168 KB Output is correct
120 Correct 20 ms 2048 KB Output is correct
121 Correct 31 ms 2040 KB Output is correct
122 Correct 20 ms 2048 KB Output is correct
123 Correct 35 ms 2168 KB Output is correct
124 Correct 20 ms 2176 KB Output is correct
125 Correct 20 ms 2176 KB Output is correct
126 Correct 19 ms 2168 KB Output is correct
127 Correct 20 ms 2048 KB Output is correct
128 Correct 18 ms 2048 KB Output is correct