Submission #1035679

# Submission time Handle Problem Language Result Execution time Memory
1035679 2024-07-26T13:33:36 Z 0npata Mechanical Doll (IOI18_doll) C++17
0 / 100
0 ms 348 KB
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;

#define vec vector
#define int long long

#define EMPTY 0
#define dbg(v)                                                                 \
	cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;

void create_circuit(int32_t M, std::vector<int32_t> A) {
	//cerr << "HELLO" << '\n';
	int N = A.size();
	map<int, int> X, Y;

	int hb = -1;
	for(int i = 0; i<32; i++) {
		if(N & 1ll << i) hb = i;
	}
	assert(hb != -1);

	std::vector<int32_t> C(M + 1, -hb-1);
	int si = hb+2;

	dbg(hb);

	auto tree = [&](int sz) {
		for(int i = 1; i<sz/2; i++) {
			X[i+si-1] = -(i*2 + si - 1);
			Y[i+si-1] = -(i*2 + 1 + si -1);
		}
		si += sz-1;
	};

	for(int i = hb+1; i>=1; i--) {
		if((1ll<<(i-1)) & N) {
			if(i > 1) {
				X[i] = -si;
				tree(1ll << (i-1));
			}
		}
		else {
			X[i] = -hb-1;
		}
		Y[i] = -i + 1;
		//cerr << X[i] << ' ';
	}
	//cerr << '\n';

	vec<bool> state(N*3+10, false);

	vec<int32_t> a = A;
	a.push_back(1e9);
	int i = 0;

	int cur = 0;
	int cnt = 0;
	do {
		cnt++;
		//cerr << cur << '\n';
		int nxt;
		if(cur < 0) {
			state[-cur] = !state[-cur];
			if(state[-cur]) {
				if(X.count(-cur) == 0) {
					X[-cur] = a[i++];
				}
				nxt = X[-cur];
			}
			else {
				if(Y.count(-cur) == 0) {
					Y[-cur] = a[i++];
				}
				nxt = Y[-cur];
			}
		}
		else {
			nxt = C[cur];
		}
		//if(cnt > 15) break;
		cur = nxt;
	} while(cur != 0);

	int S = si;
	vec<int32_t> XA(si-1, 1e9);
	vec<int32_t> YA(si-1, 1e9);

	for(auto [i, val] : X) {
		XA[i-1] = val;
	}
	for(auto [i, val] : Y) {
		YA[i-1] = val;
	}


	answer(C, XA, YA);
}

Compilation message

doll.cpp: In function 'void create_circuit(int32_t, std::vector<int>)':
doll.cpp:85:6: warning: unused variable 'S' [-Wunused-variable]
   85 |  int S = si;
      |      ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -