답안 #1041478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041478 2024-08-02T04:38:37 Z amunduzbaev 자동 인형 (IOI18_doll) C++17
0 / 100
22 ms 9644 KB
#include "doll.h"

#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;

template<class T> bool umin(T& a, const T b){ if(a > b) { a = b; return true; } return false; }
template<class T> bool umax(T& a, const T b){ if(a < b) { a = b; return true; } return false; }

void create_circuit(int m, vector<int> a) {
	int n = a.size();
	
	vector<int> c(m + 1), x_(m), y_(m);
	vector<int> cnt(m + 1);
	
	a.insert(a.begin(), 0);
	a.push_back(0);
	
	for(int i=0;i<=n;i++){
		cnt[a[i]]++;
	}
	
	vector<vector<int>> out(m + 1);
	for(int i=1;i<=n+1;i++){
		int x = a[i - 1], y = a[i];
		
		//~ out[x].push_back(y);
		
		if(cnt[y] == 1){
			out[x].push_back(y);
		}  else {
			out[x].push_back(-y);
		}
	}
	
	int last = m;
	
	auto get = [&](){
		x_.push_back(0);
		y_.push_back(0);
		
		return ++last;
	};
	
	function<int(vector<int>)> dfs = [&](vector<int> a){
		if((int)a.size() == 1){
			return a[0];
		}
		
		vector<int> l, r;
		for(int i=0;i<(int)a.size();i++){
			if(i & 1) r.push_back(a[i]);
			else l.push_back(a[i]);
		}
		
		int v = get();
		x_[v - 1] = dfs(l);
		y_[v - 1] = dfs(r);
		return -v;
	};
	
	//~ for(int i=0;i<=m;i++){
		//~ cout<<cnt[i]<<" ";
	//~ } cout<<endl;
	
	for(int i=0;i<=m;i++){
		if(!cnt[i]) continue;
		if(cnt[i] == 1){
			//~ cout<<i<<endl;
			c[i] = out[i][0];
			continue;
		}
		
		vector<int> a_(cnt[i], i);
		
		//~ cout<<i<<" : ";
		//~ for(auto x : a_) cout<<x<<" ";
		//~ cout<<endl;
		
		int root = -dfs(a_) - 1;
		x_[i - 1] = x_[root];
		y_[i - 1] = y_[root];
		
		c[i] = dfs(out[i]);
	}
		
	//~ for(int i=0;i<=m;i++){
		//~ cout<<i<<" : ";
		//~ for(auto x : out[i]) cout<<x<<" ";
		//~ cout<<endl;
	//~ }
	
	//~ for(int i=0;i<=m;i++){
		//~ cout<<c[i]<<" ";
	//~ }
	//~ cout<<endl;
	
	//~ for(int i=0;i<last;i++){
		//~ cout<<x_[i]<<" ";
	//~ } cout<<endl;
	
	//~ for(int i=0;i<last;i++){
		//~ cout<<y_[i]<<" ";
	//~ } cout<<endl;
	
	answer(c, x_, y_);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 22 ms 9644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 22 ms 9644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 22 ms 9644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB state 'Y'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB state 'Y'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB state 'Y'
2 Halted 0 ms 0 KB -