Submission #1042241

# Submission time Handle Problem Language Result Execution time Memory
1042241 2024-08-02T17:24:56 Z amunduzbaev Mechanical Doll (IOI18_doll) C++17
72.531 / 100
136 ms 10752 KB
#include "doll.h"

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

void create_circuit(int m, vector<int> a) {
	vector<int> c(m + 1, -1);
	if((int)a.size() == 1) { 
		//~ for(auto x : a){
			//~ cout<<x<<" ";
		//~ } cout<<endl;
		
		c.assign(m + 1, 0);
		
		c[0] = a[0];
		answer(c, {}, {});
		return;
	}

	c[0] = a[0];
	a.erase(a.begin());
	//~ a.push_back(0);
	
	//~ for(auto x : a){
		//~ cout<<x<<" ";
	//~ } cout<<endl;
	
	//~ cout<<"Been here: 1"<<endl;
	
	int n = a.size() + 1;
	int x_ = __lg(n);
	
	if((1 << x_) < n) x_++;
	
	vector<int> x, y;
	int last = 0;
	
	auto get = [&](){
		x.push_back(0);
		y.push_back(0);
		last++;
		
		return last;
	};
	
	//~ cout<<"Been here: 2"<<endl;
	
	function<int(int, int, vector<int>)> buildTree = [&](int l, int r, vector<int> a){
		//~ cout<<l<<" "<<r<<" : ";
		//~ for(auto x : a) cout<<x<<" ";
		//~ cout<<endl;
		
		//~ cout<<l<<" "<<r<<" "<<(int)a.size()<<endl;
		if((int)a.size() == 0){
			if(r == (1 << x_) - 1){
				if(l == r) return 0;
				
				int m = (l + r) >> 1;
				int root = get();
				
				x[root - 1] = -1;
				y[root - 1] = buildTree(m + 1, r, a);
				
				//~ cout<<"vertex: "<<-root<<" "<<x[root - 1]<<" "<<y[root - 1]<<endl;
				
				return -root;
			}
			
			return -1;
		}
		if(l == r){
			assert((int)a.size() == 1);
			return a[0];
		}
		
		int m = (l + r) >> 1;
		int l_sz = m - l + 1;
		// [l, m], [m + 1, r]
		
		int goRight = (int)a.size() - l_sz;
		vector<int> goL, goR;
		
		for(int i=0;i<(int)a.size();i++){
			if(i % 2 == 0 || (int)goR.size() == goRight){
				goL.push_back(a[i]);
			} else {
				goR.push_back(a[i]);
			}
		}
		
		int root = get();
		
		//~ int LeftRoot = buildTree(l, m, goL);
		//~ int RightRoot = buildTree(m + 1, r, goR);
		
		//~ cout<<"before: " <<LeftRoot<<" "<<RightRoot<<endl;
		
		x[root - 1] = buildTree(l, m, goL);
		y[root - 1] = buildTree(m + 1, r, goR);
		
		//~ x[root - 1] = LeftRoot;
		//~ y[root - 1] = RightRoot;
		
		//~ cout<<"vertex: "<<-root<<" "<<x[root - 1]<<" "<<y[root - 1]<<endl;
		
		return -root;
		//~ buildTree(l, m, goL);
		//~ buildTree(m + 1, r, goR);
	};
	
	buildTree(0, (1 << x_) - 1, a);
	
	vector<int> dir(last, 0);
	
	function<int(int, int)> simulate = [&](int root, int value){
		//~ cout<<root<<" "<<value<<endl;
		if(root >= 0){
			return value;
		}
		
		root = -root;
		
		dir[root - 1] ^= 1;
		if(dir[root - 1] != 0){
			x[root - 1] = simulate(x[root - 1], value);
		} else {
			y[root - 1] = simulate(y[root - 1], value);
		}
		
		return -root;
	};
	
	for(int i=0;i<(int)a.size();i++){
		simulate(-1, a[i]);
	}
	
	//~ for(int i=0;i<(int)a.size();i++){
		//~ cout<<a[i]<<" ";
	//~ } cout<<"\n";
	
	//~ for(int i=0;i<=m;i++){
		//~ cout<<c[i]<<" ";
	//~ } cout<<endl;
	
	//~ for(int i=0;i<last;i++){
		//~ cout<<x[i]<<" ";
	//~ } cout<<endl;
	
	//~ for(int i=0;i<last;i++){
		//~ cout<<y[i]<<" ";
	//~ } cout<<endl;
	
	//~ assert(last <= n + x_ * 2);
	
	answer(c, x, y);
	
	return;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 40 ms 4136 KB Output is correct
3 Correct 37 ms 4216 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Incorrect 81 ms 5556 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 40 ms 4136 KB Output is correct
3 Correct 37 ms 4216 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Incorrect 81 ms 5556 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 40 ms 4136 KB Output is correct
3 Correct 37 ms 4216 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Incorrect 81 ms 5556 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 71 ms 5324 KB Output is correct
3 Correct 68 ms 6256 KB Output is correct
4 Partially correct 130 ms 9096 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 71 ms 5324 KB Output is correct
3 Correct 68 ms 6256 KB Output is correct
4 Partially correct 130 ms 9096 KB Output is partially correct
5 Partially correct 136 ms 10732 KB Output is partially correct
6 Partially correct 127 ms 10628 KB Output is partially correct
7 Partially correct 128 ms 10624 KB Output is partially correct
8 Partially correct 126 ms 10720 KB Output is partially correct
9 Partially correct 67 ms 7056 KB Output is partially correct
10 Partially correct 127 ms 10752 KB Output is partially correct
11 Partially correct 126 ms 10532 KB Output is partially correct
12 Correct 66 ms 7316 KB Output is correct
13 Correct 67 ms 6672 KB Output is correct
14 Correct 73 ms 7652 KB Output is correct
15 Correct 71 ms 7840 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 72 ms 6652 KB Output is correct
18 Correct 71 ms 6048 KB Output is correct
19 Correct 68 ms 7328 KB Output is correct
20 Partially correct 129 ms 10716 KB Output is partially correct
21 Partially correct 129 ms 10720 KB Output is partially correct
22 Partially correct 127 ms 10544 KB Output is partially correct