답안 #1048251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048251 2024-08-08T06:01:52 Z Alihan_8 자동 인형 (IOI18_doll) C++17
47 / 100
171 ms 28024 KB
#include "doll.h"

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ln '\n'
#define all(x) x.begin(), x.end() 

template <class F, class S>
bool chmax(F &u, const S &v){
	bool flag = false;
	
	if ( u < v ){
		u = v; flag |= true;
	}
	
	return flag;
}

void create_circuit(int m, std::vector<int> A) {
	int n = A.size(), x = (n + 1) / 2;
	
	int lg = __lg(x);
	
	if ( (1 << lg) < x ) ++lg;
	
	vector <int> L(2 * n), R(2 * n);
	
	int ct = 0;
	
	auto build_tree = [&](auto build_tree, int v, int d) -> void{
		chmax(ct, v);
		
		L[v] = R[v] = -1;
		
		if ( d == 0 ) return;
		
		L[v] = v * 2, R[v] = v * 2 + 1;
		
		build_tree(build_tree, v * 2, d - 1);
		build_tree(build_tree, v * 2 + 1, d - 1);
	};
	
	build_tree(build_tree, 1, lg);
	
	vector <int> C(m + 1, -1), X(ct), Y(ct);
	
	C[0] = A[0];
	
	vector <int> state(ct + 1);
	
	auto dfs = [&](auto dfs, int v, int p) -> void{
		state[v] ^= 1;
		
		if ( v == ct && !state[v] ){ // last Vertex
			Y[v - 1] = 0; return;
		}
		
		if ( L[v] == -1 ){ // leaf vertex
			if ( state[v] > 0 ){
				X[v - 1] = (p < n ? A[p] : -1);
			} else Y[v - 1] = (p < n ? A[p] : -1);
			
			dfs(dfs, 1, p + 1);
			
			return;
		}
		
		X[v - 1] = -L[v];
		Y[v - 1] = -R[v];
		
		if ( state[v] ){
			dfs(dfs, L[v], p);
		} else dfs(dfs, R[v], p);
	};
	
	dfs(dfs, 1, 1);
	
	{ // compressing 
		vector <int> is(ct + 1);
		
		auto dfs = [&](auto dfs, int v) -> bool{
			if ( L[v] == -1 ){ // leaf
				return X[v] != -1 || Y[v] != -1;
			}
			
			bool x = dfs(dfs, L[v]) || dfs(dfs, R[v]);
			
			if ( !x ) is[v] = 1;
			
			return x;
		};
		
		dfs(dfs, 1);
		
		int cnt = 0;
		
		map <int,int> id;
		
		vector <int> x, y;
		
		auto get = [&](int u){
			if ( !id.count(u) ){
				id[u] = ++cnt;
				x.pb(0), y.pb(0);
			} return id[u];
		};
		
		auto trav = [&](auto trav, int v) -> int{
			int u = get(v);
			
			if ( is[v] ){
				x[u - 1] = y[u - 1] = -1;
				
				return u;
			}
			
			if ( L[v] == -1 ){ // leaf
				x[u - 1] = X[v - 1];
				y[u - 1] = Y[v - 1];
			} else{
				x[u - 1] = -get(L[v]);
				y[u - 1] = -get(R[v]);
				
				trav(trav, L[v]); 
				trav(trav, R[v]);
			}
			
			return u;
		};
		
		trav(trav, 1);
		
		//~ for ( int i = 0; i <= m; i++ ){
			//~ cout << i << " " << C[i] << ln;
		//~ }
		
		//~ for ( int i = 0; i < (int)id.size(); i++ ){
			//~ cout << -(i + 1) << ' ' << x[i] << ln;
			//~ cout << -(i + 1) << " " << y[i]  << ln; 
		//~ }	
		
		answer(C, x, y);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 72 ms 14792 KB Output is correct
3 Partially correct 151 ms 26032 KB Output is partially correct
4 Partially correct 155 ms 27708 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 72 ms 14792 KB Output is correct
3 Partially correct 151 ms 26032 KB Output is partially correct
4 Partially correct 155 ms 27708 KB Output is partially correct
5 Partially correct 171 ms 27960 KB Output is partially correct
6 Partially correct 153 ms 27752 KB Output is partially correct
7 Partially correct 152 ms 28024 KB Output is partially correct
8 Partially correct 159 ms 27708 KB Output is partially correct
9 Partially correct 147 ms 26048 KB Output is partially correct
10 Partially correct 158 ms 27708 KB Output is partially correct
11 Partially correct 152 ms 27820 KB Output is partially correct
12 Partially correct 164 ms 26036 KB Output is partially correct
13 Correct 74 ms 14860 KB Output is correct
14 Partially correct 154 ms 26112 KB Output is partially correct
15 Partially correct 158 ms 26424 KB Output is partially correct
16 Partially correct 3 ms 1116 KB Output is partially correct
17 Correct 73 ms 14796 KB Output is correct
18 Correct 73 ms 14660 KB Output is correct
19 Partially correct 146 ms 25920 KB Output is partially correct
20 Partially correct 154 ms 27660 KB Output is partially correct
21 Partially correct 162 ms 27960 KB Output is partially correct
22 Partially correct 160 ms 27704 KB Output is partially correct