답안 #1024786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024786 2024-07-16T10:19:30 Z fv3 자동 인형 (IOI18_doll) C++14
100 / 100
87 ms 11592 KB
#include <bits/stdc++.h>
#include "doll.h"

using namespace std;

vector<int> C;
vector<int> X, Y;
int lastSwitch = 0;
int INF = 1 << 30;

void make_connections(int cnt)
{
	int origo = -X.size() - 1;
	int index = 0;

	int nt = 1;
	while (nt < cnt)
		nt *= 2;

	vector<int> st(2 * nt), label(2 * nt);
	for (int i = 2 * nt - cnt; i < 2 * nt; i++)
		st[i] = 1;

	for (int i = nt - 1; i >= 1; i--)
		st[i] = max(st[i*2], st[i*2|1]);

	label[1] = --lastSwitch;
	for (int i = 1; i < nt; i++)
	{
		if (!st[i]) continue;

		if (st[i * 2])
		{
			if (i * 2 >= nt)
			{
				X.push_back(INF);
			}
			else
			{
				X.push_back(--lastSwitch);
				label[i*2] = lastSwitch;
			}
		}
		else
		{
			X.push_back(origo);
		}

		if ((2 * i | 1) >= nt)
		{
			Y.push_back(INF);
		}
		else
		{
			label[(2*i|1)] = --lastSwitch;
			Y.push_back(lastSwitch);
		}
	}
}

void simulate(vector<int> &A)
{
	int nxt = 0;
	int index = C[0];
	A.push_back(0);
	vector<int> state(X.size());

	while (index != 0)
	{
		if (index < 0)
		{
			if (!state[-index - 1])
			{
				state[-index-1] ^= 1;
				if (X[-index-1] == INF)
				{
					X[-index-1] = A[nxt];
				}

				index = X[-index-1];
			}
			else
			{
				state[-index-1] ^= 1;
				if (Y[-index-1] == INF)
					Y[-index-1] = A[nxt];

				index = Y[-index-1];
			}
		}
		else
		{
			index = C[index];
			nxt++;
		}
	}
}

void create_circuit(int M, vector<int> A) 
{
	vector<vector<int>> adj(M + 1);
	const int N = A.size();
	A.push_back(0);
	C = vector<int>(M + 1, -1);
	
	make_connections(A.size());
	simulate(A);
	answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void make_connections(int)':
doll.cpp:14:6: warning: unused variable 'index' [-Wunused-variable]
   14 |  int index = 0;
      |      ^~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:102:12: warning: unused variable 'N' [-Wunused-variable]
  102 |  const int N = A.size();
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 27 ms 6744 KB Output is correct
3 Correct 25 ms 5720 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 40 ms 7124 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 27 ms 6744 KB Output is correct
3 Correct 25 ms 5720 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 40 ms 7124 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 52 ms 9560 KB Output is correct
9 Correct 52 ms 10584 KB Output is correct
10 Correct 86 ms 11592 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 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 27 ms 6744 KB Output is correct
3 Correct 25 ms 5720 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 40 ms 7124 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 52 ms 9560 KB Output is correct
9 Correct 52 ms 10584 KB Output is correct
10 Correct 86 ms 11592 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 80 ms 10824 KB Output is correct
15 Correct 49 ms 8792 KB Output is correct
16 Correct 80 ms 10572 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 76 ms 11200 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 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 47 ms 7768 KB Output is correct
3 Correct 47 ms 7764 KB Output is correct
4 Correct 80 ms 9036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 47 ms 7768 KB Output is correct
3 Correct 47 ms 7764 KB Output is correct
4 Correct 80 ms 9036 KB Output is correct
5 Correct 87 ms 9912 KB Output is correct
6 Correct 75 ms 9548 KB Output is correct
7 Correct 71 ms 9800 KB Output is correct
8 Correct 70 ms 9292 KB Output is correct
9 Correct 46 ms 7764 KB Output is correct
10 Correct 67 ms 9036 KB Output is correct
11 Correct 73 ms 9032 KB Output is correct
12 Correct 46 ms 7768 KB Output is correct
13 Correct 52 ms 8280 KB Output is correct
14 Correct 49 ms 8280 KB Output is correct
15 Correct 48 ms 8536 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 42 ms 5688 KB Output is correct
18 Correct 47 ms 7768 KB Output is correct
19 Correct 44 ms 7764 KB Output is correct
20 Correct 73 ms 9020 KB Output is correct
21 Correct 66 ms 9032 KB Output is correct
22 Correct 72 ms 9036 KB Output is correct