답안 #1043255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043255 2024-08-04T06:40:55 Z yanb 자동 인형 (IOI18_doll) C++14
66.5995 / 100
58 ms 17732 KB
#include <bits/stdc++.h>

using namespace std;
    
//#define int long long
#define pii pair<int, int>

void answer(vector<signed> C, vector<signed> X, vector<signed> Y);

void dfs(vector<int> &X, vector<int> &Y, int v) {
	int u = X[-v - 1];
	if (u < -1) {
		dfs(X, Y, u);
		if (X[-u - 1] == -1 && Y[-u - 1] == -1) X[-v - 1] = -1;
	}
	u = Y[-v - 1];
	if (u < -1) {
		dfs(X, Y, u);
		if (X[-u - 1] == -1 && Y[-u - 1] == -1) Y[-v - 1] = -1;
	}
}

void create_circuit(int k, vector<int> a) {
	a.push_back(0);
	int n = a.size();

	vector<int> C(k + 1, -1), X, Y;

	int cnt = n;
	int z = 1, ord = 0;
	while (z < cnt) {
		z *= 2;
		ord++;
	}
	ord = max(1, ord);

	vector<int> p(z);
	p[0] = 0;
	for (int i = 0; i < ord; i++) {
		for (int ni = 0; ni < (1 << i); ni++) {
			p[(1 << i) + ni] = p[ni] + (1 << (ord - i - 1));
		}
	}

	for (int i = 0; i < z - n; i++) p[i] = -1;
	vector<pii> mp(z);
	for (int i = 0; i < z; i++) mp[i] = {p[i], i};
	sort(mp.begin(), mp.end());
	for (int i = z - n; i < z; i++) {
		p[mp[i].second] = i - z + n;
	}

	vector<int> v(z);
	for (int i = 0; i < z; i++) {
		v[i] = (p[i] == -1 ? -1 : a[p[i]]);
	}

	vector<int> X_(z), Y_(z);
	for (int ni = 1; ni < z / 2; ni++) {
		X_[ni] = -ni * 2 - 1;
		Y_[ni] = -ni * 2;
	}
	for (int ni = 0; ni < z / 2; ni++) {
		X_[z - ni - 1] = v[ni * 2];
		Y_[z - ni - 1] = v[ni * 2 + 1];
	}

	for (int i = 1; i < z; i++) {
		X.push_back(X_[i]);
		Y.push_back(Y_[i]);
	}

	dfs(X, Y, -1);

	/*for (int x : X) cout << x << " ";
	cout << "\n";
	for (int x : Y) cout << x << " ";
	cout << "\n\n";*/

	vector<int> Xf, Yf, f(z);
	int tm = -1;
	for (int i = 0; i < z - 1; i++) {
		if (X[i] == -1 && Y[i] == -1) continue;
		f[i] = tm;
		tm--;
	}

	/*for (int i = 0; i < z; i++) {
		cout << f[i] << " ";
	}
	cout << "\n\n";*/

	for (int i = 0; i < z; i++) {
		if (X[i] == -1 && Y[i] == -1) continue;
		Xf.push_back(X[i] < 0 ? f[-X[i] - 1] : X[i]);
		Yf.push_back(Y[i] < 0 ? f[-Y[i] - 1] : Y[i]);
	}

	/*for (int x : Xf) cout << x << " ";
	cout << "\n";
	for (int x : Yf) cout << x << " ";
	cout << "\n";*/

	answer(C, Xf, Yf);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 20 ms 8792 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 20 ms 8792 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 20 ms 8792 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Partially correct 32 ms 14720 KB Output is partially correct
3 Correct 36 ms 14504 KB Output is correct
4 Correct 48 ms 17216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Partially correct 32 ms 14720 KB Output is partially correct
3 Correct 36 ms 14504 KB Output is correct
4 Correct 48 ms 17216 KB Output is correct
5 Correct 54 ms 17732 KB Output is correct
6 Correct 51 ms 17576 KB Output is correct
7 Correct 52 ms 17728 KB Output is correct
8 Correct 58 ms 17476 KB Output is correct
9 Correct 40 ms 14504 KB Output is correct
10 Correct 58 ms 17340 KB Output is correct
11 Correct 48 ms 17220 KB Output is correct
12 Correct 34 ms 14764 KB Output is correct
13 Partially correct 36 ms 14764 KB Output is partially correct
14 Correct 34 ms 14768 KB Output is correct
15 Correct 35 ms 15024 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 28 ms 10580 KB Output is correct
18 Partially correct 35 ms 14540 KB Output is partially correct
19 Correct 34 ms 14752 KB Output is correct
20 Correct 56 ms 17444 KB Output is correct
21 Correct 50 ms 17228 KB Output is correct
22 Correct 48 ms 17220 KB Output is correct