Submission #295460

# Submission time Handle Problem Language Result Execution time Memory
295460 2020-09-09T16:56:32 Z Kastanda Mechanical Doll (IOI18_doll) C++11
100 / 100
121 ms 13012 KB
// M
#include<bits/stdc++.h>
#include "doll.h"
using namespace std;
const int N = 400005;
int n, m, k, len, ts, need, A[N], L[N], R[N], B[N];
int Solve(int l, int r)
{
	if (!need)
		return -1;
	if (r - l < 2)
	{
		need --;
		return B[l];
	}
	int v = ++ ts;
	R[v] = Solve((l + r) >> 1, r);
	L[v] = Solve(l, (l + r) >> 1);
	return -v;
}

void create_circuit(int _m, vector < int > _A)
{
	m = _m;
	n = (int)_A.size();
	for (int i = 0; i < n; i ++)
		A[i] = _A[i];
	A[n] = 0;

	if (n == 1)
	{
		vector < int > C(m + 1, 0);
		vector < int > X, Y;
		C[0] = A[0];
		C[A[0]] = 0;
		answer(C, X, Y);
		return ;
	}
	
	need = n;
	while ((1 << k) < n)
		k ++;

	vector < pair < int , int > > vec;
	for (int i = (1 << k) - n; i < (1 << k); i ++)
	{
		int ra = 0, a = i;
		for (int j = 0; j < k; j ++)
			ra = (ra << 1) | (a & 1), a >>= 1;
		vec.push_back({ra, i});
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < n; i ++)
		B[vec[i].second] = A[i + 1];

	assert(Solve(0, (1 << k)) == -1);

	vector < int > C(m + 1, -1);
	C[0] = A[0];
	vector < int > X(ts), Y(ts);
	for (int i = 0; i < ts; i ++)
		X[i] = L[i + 1], Y[i] = R[i + 1];

	answer(C, X, Y);
	return ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 47 ms 5060 KB Output is correct
3 Correct 38 ms 4828 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 12 ms 1484 KB Output is correct
6 Correct 65 ms 7344 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 47 ms 5060 KB Output is correct
3 Correct 38 ms 4828 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 12 ms 1484 KB Output is correct
6 Correct 65 ms 7344 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 68 ms 8520 KB Output is correct
9 Correct 74 ms 9148 KB Output is correct
10 Correct 116 ms 13012 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 47 ms 5060 KB Output is correct
3 Correct 38 ms 4828 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 12 ms 1484 KB Output is correct
6 Correct 65 ms 7344 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 68 ms 8520 KB Output is correct
9 Correct 74 ms 9148 KB Output is correct
10 Correct 116 ms 13012 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 109 ms 12544 KB Output is correct
15 Correct 75 ms 8096 KB Output is correct
16 Correct 104 ms 12236 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 108 ms 12668 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 61 ms 7480 KB Output is correct
3 Correct 58 ms 7476 KB Output is correct
4 Correct 95 ms 11184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 61 ms 7480 KB Output is correct
3 Correct 58 ms 7476 KB Output is correct
4 Correct 95 ms 11184 KB Output is correct
5 Correct 101 ms 12152 KB Output is correct
6 Correct 98 ms 11744 KB Output is correct
7 Correct 101 ms 11832 KB Output is correct
8 Correct 104 ms 11592 KB Output is correct
9 Correct 57 ms 7384 KB Output is correct
10 Correct 97 ms 11504 KB Output is correct
11 Correct 121 ms 11188 KB Output is correct
12 Correct 68 ms 7500 KB Output is correct
13 Correct 60 ms 7696 KB Output is correct
14 Correct 61 ms 7880 KB Output is correct
15 Correct 63 ms 8004 KB Output is correct
16 Correct 3 ms 580 KB Output is correct
17 Correct 62 ms 7412 KB Output is correct
18 Correct 61 ms 7480 KB Output is correct
19 Correct 83 ms 7452 KB Output is correct
20 Correct 95 ms 11392 KB Output is correct
21 Correct 95 ms 11260 KB Output is correct
22 Correct 113 ms 11188 KB Output is correct