답안 #131866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131866 2019-07-17T20:30:41 Z MetB 자동 인형 (IOI18_doll) C++14
100 / 100
284 ms 21808 KB
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;

int n, m, a[1000000], ptr, x[1000000], y[1000000];

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

struct Node
{
	int x;
	bool on;

	Node *l, *r;

	Node () : x (0), on (false), l (NULL), r (NULL) {}
};

Node *root, *origin;

Node* dfs_init (int n, int tl, int tr, bool rt)
{
	if (tr <= n) return root;

	Node* a = new Node ();

	if (rt) root = a;

	if (tl != tr)
	{
		a -> x = -(++ptr);
		a -> l = dfs_init (n, tl, (tl + tr) / 2, false);
		a -> r = dfs_init (n, (tl + tr) / 2 + 1, tr, false);
	}

	return a;
}

bool place_next (Node* t, int x)
{
	t -> on = !(t -> on);

	Node* to = new Node ();

	if (t -> on) to = t -> l;
	else to = t -> r;

	if (to == root) return false;
	else if (!to -> l) to -> x = x;
	else return place_next (to, x);

	return true;
}

void dfs_output (Node* t)
{
	if (!t -> l) return;

	x[-(t -> x) - 1] = t -> l -> x;
	y[-(t -> x) - 1] = t -> r -> x;

	if (t -> l != root) dfs_output (t -> l);
	if (t -> r != root) dfs_output (t -> r);
}

void create_circuit (int m, vector <int> A)
{
	origin = new Node ();

	int n = (int) A.size ();
	int n_ = n + 1;

	int start = 1, s = 0;

	while (start < n_) start <<= 1;

	dfs_init (start - n_, 1, start, true);

	int p = 0;

	while (p < n)
	{
		s++;
		if (place_next (root, A[p])) p++;
	}

	while (!place_next (root, 0));

	dfs_output (root);

	vector <int> C;

	C.push_back (-1);

	for (int i = 0; i < m; i++)
		C.push_back (-1);

	vector <int> X, Y;

	for (int i = 0; i < ptr; i++)
	{
		X.push_back (x[i]);
		Y.push_back (y[i]);
	}

	answer (C, X, Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 52 ms 8380 KB Output is correct
3 Correct 49 ms 8224 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 12 ms 1604 KB Output is correct
6 Correct 92 ms 11696 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 52 ms 8380 KB Output is correct
3 Correct 49 ms 8224 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 12 ms 1604 KB Output is correct
6 Correct 92 ms 11696 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 134 ms 14492 KB Output is correct
9 Correct 128 ms 14856 KB Output is correct
10 Correct 244 ms 21808 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 52 ms 8380 KB Output is correct
3 Correct 49 ms 8224 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 12 ms 1604 KB Output is correct
6 Correct 92 ms 11696 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 134 ms 14492 KB Output is correct
9 Correct 128 ms 14856 KB Output is correct
10 Correct 244 ms 21808 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 Correct 255 ms 21436 KB Output is correct
15 Correct 137 ms 14048 KB Output is correct
16 Correct 276 ms 21296 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 253 ms 21556 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 133 ms 13632 KB Output is correct
3 Correct 135 ms 13664 KB Output is correct
4 Correct 247 ms 20780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 133 ms 13632 KB Output is correct
3 Correct 135 ms 13664 KB Output is correct
4 Correct 247 ms 20780 KB Output is correct
5 Correct 256 ms 21136 KB Output is correct
6 Correct 284 ms 20972 KB Output is correct
7 Correct 214 ms 20960 KB Output is correct
8 Correct 261 ms 20868 KB Output is correct
9 Correct 139 ms 13660 KB Output is correct
10 Correct 216 ms 20828 KB Output is correct
11 Correct 223 ms 20768 KB Output is correct
12 Correct 120 ms 13644 KB Output is correct
13 Correct 163 ms 13936 KB Output is correct
14 Correct 148 ms 13916 KB Output is correct
15 Correct 121 ms 14008 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 122 ms 13728 KB Output is correct
18 Correct 159 ms 13660 KB Output is correct
19 Correct 116 ms 13656 KB Output is correct
20 Correct 255 ms 20796 KB Output is correct
21 Correct 255 ms 20848 KB Output is correct
22 Correct 242 ms 20788 KB Output is correct