답안 #422944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422944 2021-06-10T14:29:06 Z amoo_safar 자동 인형 (IOI18_doll) C++17
100 / 100
142 ms 10700 KB
#include "doll.h"

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second

using namespace std;

vector<int> X, Y;
int uni = 12345678;

int Solve(int gd, int bd){
	int id = X.size() + 1;
	X.pb(0); Y.pb(0);
	
	if(gd + bd == 2){
		X[id - 1] = bd ? -1 : uni;
		Y[id - 1] = gd ? uni : -1;
		return -id;
	}
	if(gd == 0){
		X[id - 1] = -1;
		Y[id - 1] = -1;
		return -id;
	}

	int n2 = (gd + bd) / 2;
	if(gd <= bd){
		X[id - 1] = -1; // Solve(0, n2);
		Y[id - 1] = Solve(gd, n2 - gd);
	} else {
		X[id - 1] = n2 == bd ? -1 : Solve(n2 - bd, bd);
		Y[id - 1] = Solve(n2, 0);
	}
	return -id;
}

void create_circuit(int m, vector<int> A) {
	X.clear();
	Y.clear();

	A.pb(0);
	// reverse(A.begin(), A.end());
	int n = A.size();
	int sz = n;
	for(int i = 0; i < 30; i++){
		if((1 << i) >= n){
			sz = (1 << i);
			break;
		}
	}

	int rt = Solve(n, sz - n);
	int S = X.size();
	// cerr << "$ " << S << '\n';
	// for(int i = 0; i < S; i++)
	// 	cerr << X[i] << ' ' << Y[i] << '\n';
	// cerr << "-----------\n";
	vector<int> mk(S, 1);
	for(int tri : A){
		int nw = -1, nrm;
		while(true){
			// cerr << "! " << nw << '\n';
			nrm = -(nw + 1);
			int nx = mk[nrm] ? X[nrm] : Y[nrm];
			assert(nx < 0 || nx == uni);
			if(nx == uni){
				(mk[nrm] ? X[nrm] : Y[nrm]) = tri;
				mk[nrm] ^= 1;
				break;
			} else {
				nw = nx;
			}
			mk[nrm] ^= 1;
		}
	}
	vector<int> C(m + 1, -1);

	// cerr << "$ " << S << '\n';
	// for(int i = 0; i < S; i++)
	// 	cerr << X[i] << ' ' << Y[i] << '\n';
	// cerr << "-----------\n";

	answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:55:6: warning: unused variable 'rt' [-Wunused-variable]
   55 |  int rt = Solve(n, sz - n);
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 46 ms 4540 KB Output is correct
3 Correct 43 ms 4292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 11 ms 1356 KB Output is correct
6 Correct 68 ms 6300 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 46 ms 4540 KB Output is correct
3 Correct 43 ms 4292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 11 ms 1356 KB Output is correct
6 Correct 68 ms 6300 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 103 ms 7016 KB Output is correct
9 Correct 87 ms 7728 KB Output is correct
10 Correct 142 ms 10700 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 46 ms 4540 KB Output is correct
3 Correct 43 ms 4292 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 11 ms 1356 KB Output is correct
6 Correct 68 ms 6300 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 103 ms 7016 KB Output is correct
9 Correct 87 ms 7728 KB Output is correct
10 Correct 142 ms 10700 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 137 ms 10096 KB Output is correct
15 Correct 82 ms 6472 KB Output is correct
16 Correct 133 ms 9904 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 128 ms 10324 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 81 ms 5556 KB Output is correct
3 Correct 76 ms 5580 KB Output is correct
4 Correct 120 ms 8520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 81 ms 5556 KB Output is correct
3 Correct 76 ms 5580 KB Output is correct
4 Correct 120 ms 8520 KB Output is correct
5 Correct 124 ms 9680 KB Output is correct
6 Correct 134 ms 9376 KB Output is correct
7 Correct 125 ms 9492 KB Output is correct
8 Correct 120 ms 9236 KB Output is correct
9 Correct 75 ms 5548 KB Output is correct
10 Correct 138 ms 9100 KB Output is correct
11 Correct 119 ms 8748 KB Output is correct
12 Correct 78 ms 5736 KB Output is correct
13 Correct 79 ms 6220 KB Output is correct
14 Correct 81 ms 6332 KB Output is correct
15 Correct 83 ms 6416 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 73 ms 6144 KB Output is correct
18 Correct 75 ms 5704 KB Output is correct
19 Correct 79 ms 5820 KB Output is correct
20 Correct 118 ms 8984 KB Output is correct
21 Correct 118 ms 8744 KB Output is correct
22 Correct 124 ms 8840 KB Output is correct