Submission #312579

#TimeUsernameProblemLanguageResultExecution timeMemory
312579tengiz05Mechanical Doll (IOI18_doll)C++17
100 / 100
138 ms11352 KiB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int sz=1, n, cnt=0;
int state[700005];
int get(int node){
	if(node >= sz){
		return (sz-n <= node-sz)?node-sz:inf;
	}
	state[node] = (state[node]+1)%2;
	if(state[node])return get(node*2);
	else return get(node*2+1);
}
void create_circuit(int m, vector<int> a) {
	a.push_back(0);
	n = a.size();
	while(sz < n)sz<<=1;
	vector<int> t(sz*2);
	for(int i=0;i<sz;i++)t[i+sz] = inf;
	int tt = 0;
	vector<int> rev(sz);
	for(int i=0;i<sz;i++)rev[i] = get(1);
//	for(auto x : rev)cout << x << ' ';
	int j = 0;
	for(int i=0;i<sz;i++){
		if(rev[i] != inf)t[rev[i]+sz] = a[j], j++;
	}
	vector<int> X, Y;
	for(int i=sz-1; i>0; i--){
		if(t[i*2] == inf && t[i*2+1] == inf)t[i] = inf;
		else {
			t[i] = --tt;
			X.push_back(t[i*2]);
			Y.push_back(t[i*2+1]);
		}
	}for(int i=0;i<(int)X.size();i++){
		if(X[i] == inf)X[i] = tt;
		if(Y[i] == inf)Y[i] = tt;
	}
	
	answer(vector<int>(m+1, tt), X, Y);
}

/*

3 15
2 1 1 1 1 3 2 1 1 1 1 1 1 1 1 1

*/
#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...