답안 #828884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828884 2023-08-17T18:27:20 Z HamletPetrosyan 자동 인형 (IOI18_doll) C++17
74 / 100
55 ms 12900 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

#define len(a) ((int)(a).size())
#define pii pair<int, int>
#define fr first
#define sc second

int n, avl, logn;
vector<int> X, Y;
vector<pii> HRT;
int CNTR = -1, S = 0;

bool dfs(int v, int x, int y, int h){
	if(h >= logn - 1){
		HRT[y] = {v, x};
		HRT[y + (1 << (logn - 1))] = {v, x + 1};
		if(x + 1 < avl) return false;
		if(x < avl) X[-v - 1] = -1;
		S++;
		return true;
	}
	int rch = --CNTR;
	if(!dfs(rch, x + (1 << (logn - h - 1)), y + (1 << h), h + 1)) return false;
	Y[-v - 1] = rch;
	int lch = --CNTR;
	if(!dfs(lch, x, y, h + 1)){
		X[-v - 1] = -1;
		S++;
		return true;
	}
	X[-v - 1] = lch;
	S++;
	return true;
}

void create_circuit(int M, vector<int> A) {
	n = A.size();
	vector<int> C(M + 1);
	C[0] = A[0];
	for (int i = 1; i <= M; ++i) C[i] = -1;
	logn = ceil(log2(n));
	avl = (1 << logn) - n;

	X.resize(2 * n);
	Y.resize(2 * n);
	HRT.resize(2 * n);
	dfs(-1, 0, 0, 0);

	X.resize(S);
	Y.resize(S);

	if(n == 1){
		C[A[0]] = 0;
		answer(C, X, Y);
		return;
	}

	// cout << avl << "\n";

	int avlcnt = 0;
	for(int i = 0, v, x, ind; i < len(HRT); i++){
		// cout << "(" << HRT[i].fr << ", " << HRT[i].sc << ") ";
		v = -HRT[i].fr - 1;
		x = HRT[i].sc;
		if(x < avl){
			avlcnt++;
			continue;
		}
		ind = i - avlcnt + 1;
		if(x % 2) Y[v] = (ind == n) ? 0 : A[ind];
		else X[v] = (ind == n) ? 0 : A[ind]; 
	}

	// cout << endl;
	// for(auto h : C) cout << h << " ";
	// cout << endl << endl;
	// for(auto h : X) cout << h << " ";
	// cout << endl;
	// for(auto h : Y) cout << h << " ";
	// cout << endl;

	answer(C, X, Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 22 ms 5460 KB Output is correct
3 Correct 20 ms 5092 KB Output is correct
4 Runtime error 1 ms 340 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 22 ms 5460 KB Output is correct
3 Correct 20 ms 5092 KB Output is correct
4 Runtime error 1 ms 340 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 22 ms 5460 KB Output is correct
3 Correct 20 ms 5092 KB Output is correct
4 Runtime error 1 ms 340 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 30 ms 8236 KB Output is correct
3 Correct 29 ms 8312 KB Output is correct
4 Correct 46 ms 12060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 30 ms 8236 KB Output is correct
3 Correct 29 ms 8312 KB Output is correct
4 Correct 46 ms 12060 KB Output is correct
5 Correct 50 ms 12696 KB Output is correct
6 Correct 49 ms 12728 KB Output is correct
7 Correct 55 ms 12900 KB Output is correct
8 Correct 47 ms 12376 KB Output is correct
9 Correct 30 ms 8272 KB Output is correct
10 Correct 47 ms 12348 KB Output is correct
11 Correct 46 ms 12092 KB Output is correct
12 Correct 30 ms 8276 KB Output is correct
13 Correct 38 ms 8568 KB Output is correct
14 Correct 32 ms 8640 KB Output is correct
15 Correct 33 ms 8816 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 30 ms 8316 KB Output is correct
18 Correct 30 ms 8268 KB Output is correct
19 Correct 30 ms 8276 KB Output is correct
20 Correct 47 ms 12252 KB Output is correct
21 Correct 46 ms 12112 KB Output is correct
22 Correct 47 ms 12096 KB Output is correct