답안 #75926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
75926 2018-09-11T15:13:16 Z ainta 자동 인형 (IOI18_doll) C++17
100 / 100
141 ms 20560 KB
#include "doll.h"
#include<cstdio>
#include<algorithm>
#include<queue>
#define N_ 101000
using namespace std;

int n, m, Out[N_], cnt, chk[N_*10], PV;

int RR[N_ * 10][2], vv[N_*10], Num[N_*10], ReNum[N_*10];

vector<int>E[N_], TP;

void Go(int a, int L, int cur, int ed) {
	if (L == 1) {
		if (RR[a][cur & 1]) {
			RR[RR[a][cur & 1]][0] = ed;
			return;
		}
		RR[a][cur & 1] = ed;
		return;
	}
	if (!RR[a][cur & 1])RR[a][cur & 1] = ++cnt;
	Go(RR[a][cur & 1], L - 1, cur >> 1, ed);
}

int Make() {
	int ret = cnt + 1;
	int i, sz = 1, cc = 0, j;
	int L = TP.size();
	while (sz < L) sz *= 2, cc++;
	
	for (i = 1; i < sz/2; i++) {
		RR[cnt + i][0] = cnt + i * 2;
		RR[cnt + i][1] = cnt + i * 2 + 1;
	}
	

	int ccc = 0;

	for (i = 0; i < sz; i++) {
		int t = 0;
		for (j = 0; j < cc; j++) {
			t = t * 2 + ((i >> j) & 1);
		}
		int nxt;
		if (t < sz - L) {
			nxt = ret;
		}
		if (t >= sz - L) {
			nxt = -TP[ccc++];
		}
		RR[cnt + sz / 2 + (t >> 1)][t & 1] = nxt;
	}

	for (i = cnt + sz - 1; i >= ret; i--) {
		int x = i - cnt;
		if (RR[i][0] >= 0 && RR[i][1] >= 0 && RR[i][0] == ret && RR[i][1] == ret) {
			RR[cnt + x / 2][x & 1] = ret;
			vv[i] = 1;
		}
	}

	cnt += sz - 1;



	return -ret;
}

void create_circuit(int M, std::vector<int> A) {
	n = A.size();
	m = M;
	E[0].push_back(A[0]);
	int i;
	A.push_back(0);
	for (i = 0; i < n; i++) {
		E[A[i]].push_back(A[i + 1]);
	}
	for (i = 0; i <= M; i++) {
		if (E[i].size() == 0) Out[i] = 0;
		else if (E[i].size() == 1)Out[i] = E[i][0];
	}
	for (i = 0; i < n; i++) {
		if (E[A[i]].size() >= 2) {
			TP.push_back(A[i + 1]);
		}
	}
	int rt = Make();
	for (i = 0; i <= M; i++)if (E[i].size() >= 2)Out[i] = rt;
	int ct = 0;
	for (i = 1; i <= cnt; i++) {
		if (!vv[i]) {
			Num[i] = ++ct;
			ReNum[ct] = i;
		}
	}
	vector<int>C(m+1), X(ct), Y(ct);
	for (i = 0; i <= m; i++) {
		C[i] = Out[i];
		if (C[i] < 0)C[i] = -Num[-Out[i]];
	}
	for (i = 0; i < ct; i++) {
		int x = RR[ReNum[i + 1]][0];
		int y = RR[ReNum[i + 1]][1];
		if (x > 0)x = Num[x];
		if (y > 0)y = Num[y];
		x = -x, y = -y;
		X[i] = x, Y[i] = y;
	}
	answer(C, X, Y);

}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 37 ms 6728 KB Output is correct
3 Correct 31 ms 6368 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 19 ms 4172 KB Output is correct
6 Correct 48 ms 8324 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 37 ms 6728 KB Output is correct
3 Correct 31 ms 6368 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 19 ms 4172 KB Output is correct
6 Correct 48 ms 8324 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 74 ms 14056 KB Output is correct
9 Correct 78 ms 13316 KB Output is correct
10 Correct 123 ms 20560 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 37 ms 6728 KB Output is correct
3 Correct 31 ms 6368 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 19 ms 4172 KB Output is correct
6 Correct 48 ms 8324 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 74 ms 14056 KB Output is correct
9 Correct 78 ms 13316 KB Output is correct
10 Correct 123 ms 20560 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 135 ms 18808 KB Output is correct
15 Correct 73 ms 13676 KB Output is correct
16 Correct 102 ms 18016 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 141 ms 19068 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2672 KB Output is correct
2 Correct 50 ms 11004 KB Output is correct
3 Correct 55 ms 12132 KB Output is correct
4 Correct 84 ms 15460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2672 KB Output is correct
2 Correct 50 ms 11004 KB Output is correct
3 Correct 55 ms 12132 KB Output is correct
4 Correct 84 ms 15460 KB Output is correct
5 Correct 99 ms 18388 KB Output is correct
6 Correct 141 ms 17872 KB Output is correct
7 Correct 99 ms 18100 KB Output is correct
8 Correct 93 ms 17444 KB Output is correct
9 Correct 55 ms 12348 KB Output is correct
10 Correct 89 ms 17108 KB Output is correct
11 Correct 87 ms 16856 KB Output is correct
12 Correct 72 ms 12988 KB Output is correct
13 Correct 62 ms 12368 KB Output is correct
14 Correct 72 ms 13736 KB Output is correct
15 Correct 70 ms 14020 KB Output is correct
16 Correct 4 ms 3020 KB Output is correct
17 Correct 55 ms 11684 KB Output is correct
18 Correct 77 ms 11616 KB Output is correct
19 Correct 58 ms 12780 KB Output is correct
20 Correct 86 ms 16676 KB Output is correct
21 Correct 86 ms 16548 KB Output is correct
22 Correct 83 ms 16292 KB Output is correct