Submission #1026101

# Submission time Handle Problem Language Result Execution time Memory
1026101 2024-07-17T14:54:22 Z Lalic Mechanical Doll (IOI18_doll) C++17
85.553 / 100
73 ms 11156 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;

int cnt, m;

void add(int ver, int root, int depth, int& tot, vector<int>& X, vector<int>& Y, vector<int>& state){
	if(!tot){
		if(Y[ver-m-1]==-1) Y[ver-m-1]=root;
		if(X[ver-m-1]==-1) X[ver-m-1]=root;
		return;
	}
	
	if(!depth){
		tot--;
		if(!tot) X[ver-m-1]=root;
		else tot--;
		return;
	}
	
	Y[ver-m-1]=++cnt;
	X.pb(-1); Y.pb(-1);
	state.pb(0);
	add(cnt, root, depth-1, tot, X, Y, state);
	
	if(!tot) X[ver-m-1]=root;
	else{
		X[ver-m-1]=++cnt;
		X.pb(-1); Y.pb(-1);
		state.pb(0);
		add(cnt, root, depth-1, tot, X, Y, state);
	}
}

void calc(int p, int qnt, vector<int>& C, vector<int>& X, vector<int>& Y, vector<int>& state){
	if(qnt==1) return;
	
	int cam=0;
	
	while((1<<cam)<qnt) cam++;
	
	C[p]=++cnt;
	X.pb(-1); Y.pb(-1);
	state.pb(0);
	
	add(cnt, cnt, cam-1, qnt, X, Y, state);
}

void create_circuit(int M, vector<int> A) {
	cnt=M;
	m=M;
	
	A.pb(0);
	vector<int> C(M+1, -1), X, Y, freq(M+1, 0), state;
	for(auto u : A) freq[u]++;
	
	int curr=0;
	for(auto u : A){
		if(C[curr]==-1) calc(curr, freq[curr], C, X, Y, state);
		
		if(C[curr]==-1){
			C[curr]=u;
			curr=u;
			continue;
		}
		
		curr=C[curr];
		
		while(1){
			if(!state[curr-m-1]){
				state[curr-m-1]=1-state[curr-m-1];
				
				if(X[curr-m-1]==-1){
					X[curr-m-1]=u;
					break;
				}
				else curr=X[curr-m-1];
			}
			else{
				state[curr-m-1]=1-state[curr-m-1];
				
				if(Y[curr-m-1]==-1){
					Y[curr-m-1]=u;
					break;
				}
				else curr=Y[curr-m-1];
			}
		}
		
		curr=u;
	}
	
	for(auto& u : C){
		if(u>m) u=m-u;
		else if(u==-1) u=0;
	}
	for(auto& u : X)
		if(u>m) u=m-u;
	for(auto& u : Y)
		if(u>m) u=m-u;
	
	answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 2904 KB Output is correct
3 Correct 10 ms 2388 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 1884 KB Output is correct
6 Correct 13 ms 3660 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 2904 KB Output is correct
3 Correct 10 ms 2388 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 1884 KB Output is correct
6 Correct 13 ms 3660 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 22 ms 6004 KB Output is correct
9 Correct 23 ms 5716 KB Output is correct
10 Correct 33 ms 9016 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 2904 KB Output is correct
3 Correct 10 ms 2388 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 1884 KB Output is correct
6 Correct 13 ms 3660 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 22 ms 6004 KB Output is correct
9 Correct 23 ms 5716 KB Output is correct
10 Correct 33 ms 9016 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 50 ms 11156 KB Output is correct
15 Correct 25 ms 6740 KB Output is correct
16 Correct 39 ms 9004 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 46 ms 9768 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 46 ms 6988 KB Output is correct
3 Correct 56 ms 5588 KB Output is correct
4 Correct 73 ms 8964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 46 ms 6988 KB Output is correct
3 Correct 56 ms 5588 KB Output is correct
4 Correct 73 ms 8964 KB Output is correct
5 Partially correct 61 ms 10312 KB Output is partially correct
6 Partially correct 54 ms 10056 KB Output is partially correct
7 Partially correct 66 ms 10232 KB Output is partially correct
8 Partially correct 51 ms 9660 KB Output is partially correct
9 Partially correct 52 ms 5840 KB Output is partially correct
10 Partially correct 69 ms 9284 KB Output is partially correct
11 Partially correct 59 ms 9024 KB Output is partially correct
12 Partially correct 53 ms 5852 KB Output is partially correct
13 Partially correct 34 ms 6860 KB Output is partially correct
14 Partially correct 35 ms 6864 KB Output is partially correct
15 Partially correct 33 ms 6876 KB Output is partially correct
16 Partially correct 1 ms 604 KB Output is partially correct
17 Partially correct 36 ms 6020 KB Output is partially correct
18 Partially correct 38 ms 5848 KB Output is partially correct
19 Partially correct 38 ms 5996 KB Output is partially correct
20 Partially correct 52 ms 9020 KB Output is partially correct
21 Partially correct 57 ms 9024 KB Output is partially correct
22 Partially correct 53 ms 9024 KB Output is partially correct