Submission #412044

#TimeUsernameProblemLanguageResultExecution timeMemory
412044MlxaMechanical Doll (IOI18_doll)C++14
28 / 100
153 ms11380 KiB
#include <bits/stdc++.h>
using namespace std;
#include "doll.h"
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second

const int MAX = 1e9;

vector<int> x, y, arr;
int solve(vector<int> idx) {
	assert(idx.size());
	if ((int)count(all(idx), -1) == (int)idx.size()) {
		return -1;
	}
	if (idx.size() == 1) {
		assert(idx[0] >= 0);
		return idx[0] == (int)arr.size() ? 0 : arr[idx[0]];
	}
	x.push_back(0), y.push_back(0);
	int v = -(int)x.size();
	// cout << v << ": ";
	// for (int e : idx) {
	// 	cout << e << " ";
	// }
	// cout << endl;

	vector<int> lef, rig;
	for (int e : idx) {
		if ((2 * lef.size() + 2 <= idx.size() && e < 0) || lef.size() <= rig.size()) {
			lef.push_back(e);
		} else {
			rig.push_back(e);
		}
	}
	// cout << "div " << idx.size() << " " << lef.size() << " " << rig.size() << endl;
	// for (int i = 0; i < (int)idx.size(); ++i) {
	// 	(i % 2 ? rig : lef).push_back(idx[i]);
	// }
	assert(0 <= -1 - v && -1 - v < (int)x.size());
	assert(0 <= -1 - v && -1 - v < (int)y.size());
	int a = solve(lef), b = solve(rig);
	x[-1 - v] = a;
	y[-1 - v] = b;
	return v;
}

void create_circuit(int m, vector<int> a) {
	arr = a;
	vector<int> c(m + 1, -1), idx((int)a.size() + 1);
	iota(all(idx), 0);
	reverse(all(idx));
	while (idx.size() & (idx.size() - 1)) {
		idx.push_back(-1);
	}
	reverse(all(idx));
	int root = solve(idx);
	assert(root == -1);
	// cout << "===" << endl;
	// for (int e : x) {
	// 	cout << e << " ";
	// }
	// cout << endl;
	// for (int e : y) {
	// 	cout << e << " ";
	// }
	// cout << endl;
	answer(c, x, y);
}

#ifdef LC
#include "grader.cpp"
#endif
#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...