Submission #75453

#TimeUsernameProblemLanguageResultExecution timeMemory
75453sevenkplusMechanical Doll (IOI18_doll)C++14
47 / 100
135 ms11316 KiB
#include "doll.h"

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

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pct __builtin_popcount

void create_circuit(int m, vector<int> a) {
	int n = a.size();
	vector<int> sc(m + 1, -1);
	sc[0] = a[0];
	
	vector<int> b;
	for (int i = 1; i < n; i ++) b.pb(a[i]);
	b.pb(0);

	int p = 1;
	while (p < n) p *= 2;
	vector<PII> s(p-1);
	vector<bool> t(p-1, 0);
	for (int i = 0; i < p/2-1; i ++)
		s[i] = mp(-(i*2+1 +1), -(i*2+2 +1));
	for (int i = 0; i < p; i ++) {
		int x = 0;
		while (x < p-1) {
			if (t[x] == 1) {
				t[x] = 0;
				x = x*2+2;
			} else {
				t[x] = 1;
				x = x*2+1;
			}
		}
		int ne = -1;
		if (i >= p-n) ne = b[i-(p-n)];
		if (x%2) s[(x-1)/2].fi = ne;
		else s[(x-1)/2].se = ne;
	}
	
	vector<int> sx, sy;
	for (int j = 0; j < (int) s.size(); j ++) {
		sx.pb(s[j].fi);
		sy.pb(s[j].se);
	}
	
	answer(sc, sx, sy);
}
#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...