Submission #248539

#TimeUsernameProblemLanguageResultExecution timeMemory
248539kostia244Mechanical Doll (IOI18_doll)C++17
28 / 100
166 ms9160 KiB
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
const int inf = 1<<29;
int n, m;
vector<int> x, y;
int build(vector<int> a, int S) {
	if(a.empty() || a.back() == -1) return -1;
	if(S == 1) return a.back();
	x.push_back(0);
	y.push_back(0);
	int id = (int)x.size();
	int cur = 0, t = min(S/2, S - (int)a.size());
	vector<int> b[2];
	for(auto i : a) {
		if(cur == 0 && t) {
			cur = 1;
			--t;
		}
		b[cur].push_back(i);
		cur ^= 1;
	}
	int tt = build(b[0], S/2);
	x[id-1] = tt;
	tt = build(b[1], S/2);
	y[id-1] = tt;
	return -id;
}
void create_circuit(int M, vector<int> A) {
	m = M, n = A.size();
	A.push_back(0);
	int t = A.size();
	while(t&(t-1)) t++;
	build(A, t);
	/*for(int i = 0; i < x.size(); i++) cout << i+1 << " " << x[i] << " " << y[i] << '\n';
	vector<int> st(x.size());
	for(int p = 0, i = 0; i < 3*n; i++) {
		cout << p << " ";
		if(p < 0) {
			p = -p - 1;
			int op = p;
			if(!st[p]) st[p] = 1, p = x[p];
			else st[p] = 0, p = y[p];
		} else p = -1;
	}
	cout << '\n';*/
	answer(vector<int>(m+1, -1), x, y);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...