답안 #978151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978151 2024-05-09T00:36:18 Z happypotato 자동 인형 (IOI18_doll) C++17
53 / 100
106 ms 16616 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
void create_circuit(int m, vector<int> a) {
	int n = a.size();
	int reidx[m + 1];
	for (int i = 1; i <= m; i++) reidx[i] = 0;
	for (int x : a) reidx[x]++;
	int bruh[m + 1];
	for (int i = 1; i < n; i++) bruh[a[i - 1]] = a[i];
	bruh[a[n - 1]] = 0;
	int base = 0;
	vector<int> C(m + 1);
	C[0] = a[0];
	for (int i = 1; i <= m; i++) {
		if (reidx[i] == 0) {
			C[i] = 0;
		} else if (reidx[i] == 1) {
			C[i] = bruh[i];
			reidx[i] = 0;
		} else if (reidx[i] >= 2) {
			reidx[i] = ++base;
			C[i] = -reidx[i];
		}
	}
 
	vector<int> sto[base + 1];
	for (int i = 1; i < n; i++) {
		sto[reidx[a[i - 1]]].pb(a[i]);
	}
	sto[reidx[a[n - 1]]].pb(0);
	// for (int i = 1; i <= m; i++) cerr << reidx[i] << ' ';
	// cerr << endl;
	// for (int i = 1; i <= base; i++) {
	// 	for (int x : sto[i]) cerr << x << ' ';
	// 	cerr << endl;
	// }
 
	vector<pii> nxt[2];
	bool flag = false;
	vector<int> access;
	vector<bool> state;
	auto gentree = [&](auto&& self, int sz) {
		if (sz == 2) {
			nxt[flag] = {{-2, -2}};
			return;
		}
		self(self, (sz + 1) / 2);
		flag ^= 1;
		nxt[flag] = {{-1, -1}};
		for (int i = 0; i < 2; i++) {
			int buff = nxt[flag].size();
			if (i == 0) nxt[flag][0].ff = buff;
			else nxt[flag][0].ss = buff;
			for (pii cur : nxt[flag ^ 1]) {
				if (cur.ff != -2) cur.ff += buff;
				if (cur.ss != -2) cur.ss += buff;
				nxt[flag].pb(cur);
			}
		}
		if (sz % 2 == 1) {
			access.resize(nxt[flag].size(), 0);
			int st = 0;
			while (true) {
				if (!access[st]) {
					access[st] = !access[st];
					if (nxt[flag][st].ff == -2) {
						nxt[flag][st].ff = 0; break;
					}
					st = nxt[flag][st].ff;
				} else {
					access[st] = !access[st];
					if (nxt[flag][st].ss == -2) {
						nxt[flag][st].ss = 0; break;
					}
					st = nxt[flag][st].ss;
				}
			}
		}
	};
	auto gen = [&](auto&& self, int sz) -> int {
		nxt[0].clear(); nxt[1].clear();
		flag = false;
		gentree(gentree, sz);
		int used = nxt[flag].size();
		int dirs = used;
		state.resize(used, 0);
		access.clear();
		int cnt = 0;
		// cerr << "Gen size " << sz << ":\n";
		// for (pii cur : nxt) cerr << cur.ff << ' ' << cur.ss << endl;
		// cerr << "End" << endl;
		do {
			int st = 0;
			while (true) {
				if (!state[st]) {
					state[st] = !state[st]; cnt++;
					if (nxt[flag][st].ff == -2) {
						nxt[flag][st].ff = dirs++;
						break;
					} else {
						st = nxt[flag][st].ff;
					}
				} else {
					state[st] = !state[st]; cnt--;
					if (nxt[flag][st].ss == -2) {
						nxt[flag][st].ss = dirs++;
						break;
					} else {
						st = nxt[flag][st].ss;
					}
				}
			}
		} while (cnt > 0);
		// cerr << "Gen size " << sz << ":\n";
		// for (pii cur : nxt) cerr << cur.ff << ' ' << cur.ss << endl;
		// cerr << "End" << endl;
		return used;
	};
 
	vector<int> X(base), Y(base);
	int cnt = base;
	for (int i = 1; i <= base; i++) {
		if (sto[i].size() == 1) {
			X[i - 1] = -i;
			Y[i - 1] = sto[i].front();
			continue;
		}
		int assign = gen(gen, sto[i].size());
 
		auto decrypt = [&](int x) -> int {
			if (x == 0) return -i;
			else if (x < assign) return -(x + cnt);
			else return sto[i][x - assign];
		};
		// cerr << "Gen " << i << ": \n";
		// cerr << assign << endl;
		// for (pii cur : nxt) cerr << cur.ff << ' ' << cur.ss << endl;
		// cerr << "End of gen " << i << endl;
		X[i - 1] = decrypt(nxt[flag][0].ff); Y[i - 1] = decrypt(nxt[flag][0].ss);
		for (int j = 1; j < (int)(nxt[flag].size()); j++) {
			// cerr << "decrypt " << nxt[j].ff << ' ' << decrypt(nxt[j].ff) << endl;
			X.pb(decrypt(nxt[flag][j].ff));
			Y.pb(decrypt(nxt[flag][j].ss));
		}
		cnt = (int)(X.size());
	}
 
	answer(C, X, Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 3544 KB Output is correct
3 Correct 11 ms 2780 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 8 ms 2400 KB Output is correct
6 Correct 17 ms 4312 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 3544 KB Output is correct
3 Correct 11 ms 2780 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 8 ms 2400 KB Output is correct
6 Correct 17 ms 4312 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 35 ms 8804 KB Output is correct
9 Correct 40 ms 7900 KB Output is correct
10 Correct 55 ms 13148 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 3544 KB Output is correct
3 Correct 11 ms 2780 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 8 ms 2400 KB Output is correct
6 Correct 17 ms 4312 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 35 ms 8804 KB Output is correct
9 Correct 40 ms 7900 KB Output is correct
10 Correct 55 ms 13148 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 67 ms 13072 KB Output is correct
15 Correct 37 ms 7044 KB Output is correct
16 Correct 54 ms 10460 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 61 ms 12308 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 46 ms 7680 KB Output is correct
3 Partially correct 75 ms 13900 KB Output is partially correct
4 Partially correct 90 ms 14216 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 46 ms 7680 KB Output is correct
3 Partially correct 75 ms 13900 KB Output is partially correct
4 Partially correct 90 ms 14216 KB Output is partially correct
5 Partially correct 80 ms 13804 KB Output is partially correct
6 Partially correct 85 ms 14096 KB Output is partially correct
7 Partially correct 84 ms 13980 KB Output is partially correct
8 Partially correct 86 ms 14588 KB Output is partially correct
9 Partially correct 69 ms 11924 KB Output is partially correct
10 Partially correct 106 ms 16616 KB Output is partially correct
11 Partially correct 91 ms 14704 KB Output is partially correct
12 Partially correct 59 ms 9980 KB Output is partially correct
13 Partially correct 54 ms 9712 KB Output is partially correct
14 Partially correct 54 ms 9328 KB Output is partially correct
15 Partially correct 52 ms 9268 KB Output is partially correct
16 Partially correct 2 ms 604 KB Output is partially correct
17 Partially correct 60 ms 8092 KB Output is partially correct
18 Partially correct 54 ms 8620 KB Output is partially correct
19 Partially correct 50 ms 8724 KB Output is partially correct
20 Partially correct 65 ms 11352 KB Output is partially correct
21 Partially correct 80 ms 12968 KB Output is partially correct
22 Partially correct 69 ms 10648 KB Output is partially correct