답안 #212999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212999 2020-03-24T18:16:56 Z mode149256 자동 인형 (IOI18_doll) C++14
6 / 100
101 ms 12308 KB
/*input

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

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

vi C;
vi X, Y;
int S = 0;

vii iseina;
int N;
int truksta;
int n;
int pradSw;
int maxLvl;
vpi place;

int nxtS() {
	X.emplace_back(0);
	Y.emplace_back(0);
	S++;
	return -S;
}

void make(int sw, int currLvl, int pos) {
	// printf("sw = %d\n", sw);
	int manoMedyElm = (1 << (maxLvl - currLvl + 1));
	if (manoMedyElm <= truksta) {
		X[sw] = Y[sw] = pradSw;
		truksta -= manoMedyElm;
		return;
	}

	if (currLvl == maxLvl) {
		if (!truksta) place[pos] = {sw, 0};
		else truksta--;

		pos |= (1 << currLvl);
		place[pos] = {sw, 1};
	} else {
		X[sw] = nxtS();
		Y[sw] = nxtS();

		make(-X[sw], currLvl + 1, pos);
		make(-Y[sw], currLvl + 1, pos | (1 << currLvl));
	}
}


void daryk(int m) {
	int sz = iseina[m].size();
	n =	(1 << (int)ceil(log2(sz)));
	maxLvl = log2(n);
	maxLvl--;
	truksta = n - sz;

	// printf("sz = %d, n = %d, mxlvl = %d,truksta = %d\n", sz, n, maxLvl, truksta);
	place = vpi(n, pi(0, 0));

	C[m] = nxtS();
	pradSw = C[m];

	make(-C[m], 0, 0);

	// printf("m = %d, sz = %d, n = %d, place:\n", m, sz, n);
	// for (auto u : place)
	// printf("%d %d\n", u.x, u.y);
	// printf("\n");

	int j = 0;
	for (int i = 0; i < sz; ++i)
	{
		while (j < n and !place[j].x) j++;
		assert(j < n);

		int h = place[j].x;

		// printf("i = %d, iseina = %d, h = %d\n", i, iseina[m][i], h);
		if (place[j].y) Y[h] = iseina[m][i];
		else X[h] = iseina[m][i];
		j++;
	}
}

void create_circuit(int M, vi A) {
	N = A.size();
	C = vi(M + 1);
	iseina = vii(M + 1);
	A.emplace_back(0);

	C[0] = A[0];

	for (int i = 0; i < N; ++i)
		iseina[A[i]].emplace_back(A[i + 1]);

	X.emplace_back(0);
	Y.emplace_back(0);

	for (int i = 1; i <= M; ++i)
	{
		if (iseina[i].empty()) C[i] = 0;
		else if (iseina[i].size() == 1) C[i] = iseina[i][0];
		else daryk(i);
	}
	X.erase(X.begin());
	Y.erase(Y.begin());


	// printf("S = %d\n", S);
	// print(C, "C: ");
	// for (int i = 0; i < S; ++i) printf("%d ", X[i]); printf("\n");
	// for (int i = 0; i < S; ++i) printf("%d ", Y[i]); printf("\n");

	answer(C, X, Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 39 ms 6336 KB Output is correct
3 Correct 36 ms 5180 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 14 ms 3788 KB Output is correct
6 Correct 44 ms 7848 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 39 ms 6336 KB Output is correct
3 Correct 36 ms 5180 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 14 ms 3788 KB Output is correct
6 Correct 44 ms 7848 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 65 ms 7900 KB Output is correct
9 Correct 94 ms 9124 KB Output is correct
10 Correct 101 ms 12308 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 39 ms 6336 KB Output is correct
3 Correct 36 ms 5180 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 14 ms 3788 KB Output is correct
6 Correct 44 ms 7848 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 65 ms 7900 KB Output is correct
9 Correct 94 ms 9124 KB Output is correct
10 Correct 101 ms 12308 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Runtime error 64 ms 11540 KB Execution killed with signal 6
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -