답안 #802990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802990 2023-08-02T17:27:23 Z IvanJ 자동 인형 (IOI18_doll) C++17
100 / 100
103 ms 11508 KB
#include "doll.h"
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int inf = 1e9;
int P = 0, SZ = 0;
vector<int> state;

int gen_switch(int N, int to_kill, int &S, vector<int> &X, vector<int> &Y) {
	if(N == to_kill) return inf;
	if(N == 1) return inf + 1;
	int L, R;
	if(to_kill <= (N >> 1)) {
		L = gen_switch(N >> 1, to_kill, S, X, Y);
		R = gen_switch(N >> 1, 0, S, X, Y);
	} else {
		L = inf;
		R = gen_switch(N >> 1, to_kill - (N >> 1), S, X, Y);
	}
	
	int root = --S;
	X.pb(L), Y.pb(R), state.pb(0);
	return root;
}

int simulate(int root, int x, vector<int> &A, vector<int> &X, vector<int> &Y) {
	if(x == inf + 1) return A[P++];
	int pos = -x - 1;
	if(state[pos] == 0 && X[pos] != root) 
		X[pos] = simulate(root, X[pos], A, X, Y);
	if(state[pos] == 1 && Y[pos] != root) 
		Y[pos] = simulate(root, Y[pos], A, X, Y);
	state[pos] ^= 1;
	return x;
}

void create_circuit(int M, vector<int> A) {
	A.pb(0);
	int S = 0, N = (int)A.size();
	int pot = 1, K = 0;
	while(pot < N) pot <<= 1, K++;
	vector<int> C, X, Y;
	
	int root = gen_switch(pot, pot - N, S, X, Y);
	for(int i = 0;i < abs(S);i++) {
		if(X[i] == inf) X[i] = root;
		if(Y[i] == inf) Y[i] = root;
	}
	C = vector<int>(M + 1, root);
	while(P < N)
		simulate(root, root, A, X, Y);
	answer(C, X, Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 37 ms 4180 KB Output is correct
3 Correct 41 ms 4320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 57 ms 6828 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 37 ms 4180 KB Output is correct
3 Correct 41 ms 4320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 57 ms 6828 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 68 ms 7264 KB Output is correct
9 Correct 70 ms 7896 KB Output is correct
10 Correct 97 ms 11508 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 37 ms 4180 KB Output is correct
3 Correct 41 ms 4320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 57 ms 6828 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 68 ms 7264 KB Output is correct
9 Correct 70 ms 7896 KB Output is correct
10 Correct 97 ms 11508 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 97 ms 10840 KB Output is correct
15 Correct 62 ms 6616 KB Output is correct
16 Correct 93 ms 10352 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 96 ms 10976 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 61 ms 5140 KB Output is correct
3 Correct 65 ms 5132 KB Output is correct
4 Correct 89 ms 8056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 61 ms 5140 KB Output is correct
3 Correct 65 ms 5132 KB Output is correct
4 Correct 89 ms 8056 KB Output is correct
5 Correct 97 ms 8916 KB Output is correct
6 Correct 93 ms 8500 KB Output is correct
7 Correct 93 ms 8632 KB Output is correct
8 Correct 90 ms 8244 KB Output is correct
9 Correct 76 ms 5064 KB Output is correct
10 Correct 92 ms 8288 KB Output is correct
11 Correct 103 ms 8032 KB Output is correct
12 Correct 63 ms 5068 KB Output is correct
13 Correct 76 ms 5380 KB Output is correct
14 Correct 63 ms 5508 KB Output is correct
15 Correct 64 ms 5768 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 56 ms 6484 KB Output is correct
18 Correct 63 ms 5136 KB Output is correct
19 Correct 70 ms 5128 KB Output is correct
20 Correct 90 ms 8076 KB Output is correct
21 Correct 90 ms 8028 KB Output is correct
22 Correct 90 ms 8044 KB Output is correct