답안 #830731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830731 2023-08-19T09:53:01 Z tranxuanbach 자동 인형 (IOI18_doll) C++17
100 / 100
85 ms 18076 KB
#include "doll.h"

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

#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define isz(a) ((signed)a.size())

const int N = 2e5 + 5, M = 1e5 + 5, S = 2 * N;
const int inf = 1e9 + 7;

int n, m;
int a[N];

int s;
int ans[M];
int ansx[S], ansy[S];

int layer;
int order[S];
vector <pair <int, int>> leaves;
int par[S];

int index_reorder[S];

void reorder(){
	int cntdone = 0;
	ForE(u, 1, s){
		if (ansx[u] == inf and ansy[u] == inf){
			continue;
		}
		index_reorder[u] = ++cntdone;
	}
	ForE(u, 1, s){
		if (ansx[u] == inf and ansy[u] == inf){
			continue;
		}
		if (ansx[u] < 0){
			ansx[u] = -index_reorder[-ansx[u]];
		}
		if (ansy[u] < 0){
			ansy[u] = -index_reorder[-ansy[u]];
		}
		swap(ansx[u], ansx[index_reorder[u]]);
		swap(ansy[u], ansy[index_reorder[u]]);
	}
	s = cntdone;
}

void create_circuit(int _m, vector <int> _a){
	n = isz(_a);
	m = _m;
	For(i, 0, n){
		a[i] = _a[i];
	}

	a[n] = 0;
	n++;

	ans[0] = -1;
	ForE(i, 1, m){
		ans[i] = -1;
	}
	fill(ansx + 1, ansx + S, inf);
	fill(ansy + 1, ansy + S, inf);
	
	layer = 0;
	while ((1 << layer) < n){
		layer++;
	}
	s = (1 << layer) - 1;

	FordE(u, -1, -(1 << (layer - 1)) + 1){
		ansx[-u] = u * 2;
		par[-(u * 2)] = u;
		ansy[-u] = u * 2 - 1;
		par[-(u * 2 - 1)] = u;
	}
	For(i, 0, (1 << layer)){
		int u = 0;
		For(bit, 0, layer){
			u = u * 2 + (i >> bit & 1);
		}
		order[u] = i;
	}
	For(u, (1 << layer) - n, (1 << layer)){
		leaves.emplace_back(order[u], u);
	}
	sort(leaves.begin(), leaves.end());
	For(i, 0, n){
		int u = leaves[i].second;
		int p = -(u / 2) - (1 << (layer - 1));
		if (u % 2 == 0){
			ansx[-p] = a[i];
		}
		else{
			ansy[-p] = a[i];
		}
	}

	ForE(u, -s, -1){
		if (ansx[-u] == inf and ansy[-u] == inf){
			int p = par[-u];
			if (ansx[-p] == u){
				ansx[-p] = inf;
			}
			else{
				ansy[-p] = inf;
			}
			continue;
		}
		if (ansy[-u] == inf){
			ansy[-u] = -1;
		}
		if (ansx[-u] == inf){
			ansx[-u] = -1;
		}
	}
	reorder();
	answer(vector <int>(ans, ans + m + 1), vector <int>(ansx + 1, ansx + s + 1), vector <int>(ansy + 1, ansy + s + 1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 29 ms 9500 KB Output is correct
3 Correct 27 ms 9020 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 8 ms 4564 KB Output is correct
6 Correct 43 ms 11360 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 29 ms 9500 KB Output is correct
3 Correct 27 ms 9020 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 8 ms 4564 KB Output is correct
6 Correct 43 ms 11360 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 61 ms 13680 KB Output is correct
9 Correct 51 ms 14220 KB Output is correct
10 Correct 76 ms 18076 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 29 ms 9500 KB Output is correct
3 Correct 27 ms 9020 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 8 ms 4564 KB Output is correct
6 Correct 43 ms 11360 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 61 ms 13680 KB Output is correct
9 Correct 51 ms 14220 KB Output is correct
10 Correct 76 ms 18076 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 78 ms 17648 KB Output is correct
15 Correct 51 ms 13196 KB Output is correct
16 Correct 85 ms 17316 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 74 ms 17840 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3388 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3384 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 44 ms 12216 KB Output is correct
3 Correct 44 ms 12184 KB Output is correct
4 Correct 78 ms 15856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 44 ms 12216 KB Output is correct
3 Correct 44 ms 12184 KB Output is correct
4 Correct 78 ms 15856 KB Output is correct
5 Correct 76 ms 17192 KB Output is correct
6 Correct 71 ms 16924 KB Output is correct
7 Correct 78 ms 17052 KB Output is correct
8 Correct 83 ms 16648 KB Output is correct
9 Correct 44 ms 12216 KB Output is correct
10 Correct 69 ms 16516 KB Output is correct
11 Correct 70 ms 16284 KB Output is correct
12 Correct 44 ms 12472 KB Output is correct
13 Correct 46 ms 12856 KB Output is correct
14 Correct 49 ms 12932 KB Output is correct
15 Correct 47 ms 13112 KB Output is correct
16 Correct 3 ms 3668 KB Output is correct
17 Correct 41 ms 11428 KB Output is correct
18 Correct 44 ms 12472 KB Output is correct
19 Correct 44 ms 12476 KB Output is correct
20 Correct 69 ms 16488 KB Output is correct
21 Correct 68 ms 16220 KB Output is correct
22 Correct 68 ms 16272 KB Output is correct