답안 #769080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769080 2023-06-29T07:04:35 Z SanguineChameleon 자동 인형 (IOI18_doll) C++17
53 / 100
57 ms 10004 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] > 3) {
			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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3028 KB Output is correct
3 Correct 11 ms 2356 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 2260 KB Output is correct
6 Correct 19 ms 3412 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3028 KB Output is correct
3 Correct 11 ms 2356 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 2260 KB Output is correct
6 Correct 19 ms 3412 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 26 ms 4816 KB Output is correct
9 Correct 28 ms 4892 KB Output is correct
10 Correct 41 ms 7100 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 3028 KB Output is correct
3 Correct 11 ms 2356 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 2260 KB Output is correct
6 Correct 19 ms 3412 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 26 ms 4816 KB Output is correct
9 Correct 28 ms 4892 KB Output is correct
10 Correct 41 ms 7100 KB Output is correct
11 Correct 1 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 52 ms 9480 KB Output is correct
15 Incorrect 56 ms 9668 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 35 ms 4924 KB Output is correct
3 Partially correct 48 ms 8012 KB Output is partially correct
4 Partially correct 51 ms 8788 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 35 ms 4924 KB Output is correct
3 Partially correct 48 ms 8012 KB Output is partially correct
4 Partially correct 51 ms 8788 KB Output is partially correct
5 Partially correct 57 ms 10004 KB Output is partially correct
6 Partially correct 56 ms 9652 KB Output is partially correct
7 Partially correct 55 ms 9852 KB Output is partially correct
8 Partially correct 53 ms 9356 KB Output is partially correct
9 Partially correct 46 ms 8016 KB Output is partially correct
10 Partially correct 56 ms 9256 KB Output is partially correct
11 Partially correct 51 ms 8872 KB Output is partially correct
12 Partially correct 46 ms 8272 KB Output is partially correct
13 Correct 31 ms 5296 KB Output is correct
14 Partially correct 49 ms 8896 KB Output is partially correct
15 Partially correct 55 ms 9140 KB Output is partially correct
16 Partially correct 2 ms 596 KB Output is partially correct
17 Correct 28 ms 4916 KB Output is correct
18 Correct 28 ms 4948 KB Output is correct
19 Partially correct 46 ms 8232 KB Output is partially correct
20 Partially correct 52 ms 9140 KB Output is partially correct
21 Partially correct 52 ms 8844 KB Output is partially correct
22 Partially correct 52 ms 8868 KB Output is partially correct