Submission #769081

# Submission time Handle Problem Language Result Execution time Memory
769081 2023-06-29T07:05:47 Z SanguineChameleon Mechanical Doll (IOI18_doll) C++17
63 / 100
59 ms 10072 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> A, C, X, Y, all_cnt, cur_cnt;
int N, M, K;

void build(int id, int depth, int cur) {
	if (depth == K - 1) {
		X[id - 1] = (cur < N - 1 ? A[cur + 1] : (cur == ((1 << K) - 1) ? 0 : -1));
		cur += 1 << depth;
		Y[id - 1] = (cur < N - 1 ? A[cur + 1] : (cur == ((1 << K) - 1) ? 0 : -1));
		return;
	}
	X[id - 1] = -(id * 2);
	Y[id - 1] = -(id * 2 + 1);
	build(id * 2, depth + 1, cur);
	build(id * 2 + 1, depth + 1, cur + (1 << depth));
}

void create_circuit(int _M, vector<int> _A) {
	A = _A;
	N = A.size();
	M = _M;
	all_cnt.resize(M + 1);
	cur_cnt.resize(M + 1);
	for (int i = 0; i < N; i++) {
		all_cnt[A[i]]++;
	}
	bool sub3 = true;
	for (int i = 1; i <= M; i++) {
		if (all_cnt[i] > 4) {
			sub3 = false;
			break;
		}
	}
	if (sub3) {
		C.resize(M + 1);
		C[0] = A[0];
		int K = 0;
		for (int i = 1; i <= M; i++) {
			if (all_cnt[i] == 2) {
				K++;
				C[i] = -K;
				X.push_back(0);
				Y.push_back(0);
			}
			if (all_cnt[i] == 3) {
				K++;
				X.push_back(-(K + 1));
				Y.push_back(-(K + 2));
				C[i] = -K;
				K++;
				X.push_back(0);
				Y.push_back(-(K - 1));
				K++;
				X.push_back(0);
				Y.push_back(0);
			}
			if (all_cnt[i] == 4) {
				K++;
				X.push_back(-(K + 1));
				Y.push_back(-(K + 2));
				C[i] = -K;
				K++;
				X.push_back(0);
				Y.push_back(0);
				K++;
				X.push_back(0);
				Y.push_back(0);
			}
		}
		for (int i = 0; i < N; i++) {
			cur_cnt[A[i]]++;
			int nxt = (i + 1 < N ? A[i + 1] : 0);
			if (all_cnt[A[i]] == 1) {
				C[A[i]] = nxt;
			}
			if (all_cnt[A[i]] == 2) {
				if (cur_cnt[A[i]] == 1) {
					X[-C[A[i]] - 1] = nxt;
				}
				else {
					Y[-C[A[i]] - 1] = nxt;
				}
			}
			if (all_cnt[A[i]] == 3) {
				if (cur_cnt[A[i]] == 1) {
					X[-C[A[i]] + 1 - 1] = nxt;
				}
				if (cur_cnt[A[i]] == 2) {
					X[-C[A[i]] + 2 - 1] = nxt;
				}
				if (cur_cnt[A[i]] == 3) {
					Y[-C[A[i]] + 2 - 1] = nxt;
				}
			}
			if (all_cnt[A[i]] == 4) {
				if (cur_cnt[A[i]] == 1) {
					X[-C[A[i]] + 1 - 1] = nxt;
				}
				if (cur_cnt[A[i]] == 2) {
					X[-C[A[i]] + 2 - 1] = nxt;
				}
				if (cur_cnt[A[i]] == 3) {
					Y[-C[A[i]] + 1 - 1] = nxt;
				}
				if (cur_cnt[A[i]] == 4) {
					Y[-C[A[i]] + 2 - 1] = nxt;
				}
			}
		}
		answer(C, X, Y);
		return;
	}
	K = 0;
	while ((1 << K) < N) {
		K++;
	}
	C.resize(M + 1, -1);
	C[0] = A[0];
	if (K == 0) {
		answer(C, X, Y);
		return;
	}
	X.resize((1 << K) - 1);
	Y.resize((1 << K) - 1);
	build(1, 0, 0);
	answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3028 KB Output is correct
3 Correct 11 ms 2260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 2260 KB Output is correct
6 Correct 16 ms 3388 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3028 KB Output is correct
3 Correct 11 ms 2260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 2260 KB Output is correct
6 Correct 16 ms 3388 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 26 ms 4832 KB Output is correct
9 Correct 26 ms 4864 KB Output is correct
10 Correct 40 ms 7196 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3028 KB Output is correct
3 Correct 11 ms 2260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 2260 KB Output is correct
6 Correct 16 ms 3388 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 26 ms 4832 KB Output is correct
9 Correct 26 ms 4864 KB Output is correct
10 Correct 40 ms 7196 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 53 ms 9480 KB Output is correct
15 Correct 34 ms 4964 KB Output is correct
16 Correct 45 ms 7876 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 8796 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 28 ms 4916 KB Output is correct
3 Partially correct 46 ms 8064 KB Output is partially correct
4 Partially correct 51 ms 8776 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 28 ms 4916 KB Output is correct
3 Partially correct 46 ms 8064 KB Output is partially correct
4 Partially correct 51 ms 8776 KB Output is partially correct
5 Partially correct 55 ms 10072 KB Output is partially correct
6 Partially correct 55 ms 9764 KB Output is partially correct
7 Partially correct 59 ms 9908 KB Output is partially correct
8 Partially correct 53 ms 9404 KB Output is partially correct
9 Partially correct 47 ms 8020 KB Output is partially correct
10 Partially correct 52 ms 9300 KB Output is partially correct
11 Partially correct 51 ms 8884 KB Output is partially correct
12 Partially correct 46 ms 8264 KB Output is partially correct
13 Correct 31 ms 5336 KB Output is correct
14 Partially correct 48 ms 8864 KB Output is partially correct
15 Partially correct 50 ms 9108 KB Output is partially correct
16 Partially correct 2 ms 596 KB Output is partially correct
17 Correct 28 ms 4920 KB Output is correct
18 Correct 35 ms 4920 KB Output is correct
19 Partially correct 46 ms 8288 KB Output is partially correct
20 Partially correct 53 ms 9136 KB Output is partially correct
21 Partially correct 52 ms 8800 KB Output is partially correct
22 Partially correct 51 ms 8872 KB Output is partially correct