답안 #75483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
75483 2018-09-09T21:46:19 Z sevenkplus 자동 인형 (IOI18_doll) C++14
63 / 100
126 ms 11832 KB
#include "doll.h"

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

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pct __builtin_popcount

#define INF 1000000007

vector<PII> ff(vector<int> a) {
	int n = (int) a.size();
	int p = 1;
	while (p < n) p *= 2;
	vector<PII> s(p-1);
	vector<bool> t(p-1, 0);
	for (int i = 0; i < p/2-1; i ++)
		s[i] = mp(-(i*2+1 +1), -(i*2+2 +1));
	for (int i = 0; i < p; i ++) {
		int x = 0;
		while (x < p-1) {
			if (t[x] == 1) {
				t[x] = 0;
				x = x*2+2;
			} else {
				t[x] = 1;
				x = x*2+1;
			}
		}
		int ne = -1;
		if (i >= p-n) ne = a[i-(p-n)];
		if (x%2) s[(x-1)/2].fi = ne;
		else s[(x-1)/2].se = ne;
	}
	return s;
}
 
bool gg(int m, vector<int> a) {
	int n = a.size();
	vector<int> sc(m + 1, -1);
	sc[0] = a[0];
	
	vector<vector<int> > p(m+1);
	for (int i = 0; i < n; i ++) {
		int ne = 0;
		if (i != n-1) ne = a[i+1];
		p[a[i]].pb(ne);
		if (p[a[i]].size() >= 5) return false;
	}
	
	vector<int> sx, sy;
	int nc = 0;
	for (int i = 1; i <= m; i ++) {
		if (p[i].empty()) {
			sc[i] = 0;
			continue;
		}
		if (p[i].size() == 1) {
			sc[i] = p[i][0];
			continue;
		}
		vector<PII> v = ff(p[i]);
		sc[i] = -(nc+1);
		for (int j = 0; j < (int) v.size(); j ++) {
			int w = v[j].fi;
			if (w < 0) w -= nc;
			sx.pb(w);
			w = v[j].se;
			if (w < 0) w -= nc;
			sy.pb(w);
		}
		nc += (int) v.size();
	}
	answer(sc, sx, sy);
	return true;
}

void create_circuit(int m, vector<int> a) {
	if (gg(m, a)) return;
	int n = a.size();
	a.pb(0);
	vector<int> sc(m + 1, 0);
	sc[0] = a[0];
	if (n == 1) {
		answer(sc, {}, {});
		return;
	}
	for (int i = 1; i <= m; i ++) sc[i] = -1;
	
	int p = 1;
	while (p < n) p *= 2;
	vector<int> wx(p-1, INF);
	vector<int> wy(p-1, INF);
	vector<bool> t(p-1, 0);
	for (int i = 0; i < p/2-1; i ++) {
		wx[i] = -(i*2+1 +1);
		wy[i] = -(i*2+2 +1);
	}
	for (int i = 0; i < p; i ++) {
		int x = 0;
		while (x < p-1) {
			if (t[x] == 1) {
				t[x] = 0;
				x = x*2+2;
			} else {
				t[x] = 1;
				x = x*2+1;
			}
		}
		int ne = -1;
		if (i >= p-n) ne = a[i-(p-n)+1];
		if (x%2) wx[(x-1)/2] = ne;
		else wy[(x-1)/2] = ne;
	}

	answer(sc, wx, wy);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 31 ms 6652 KB Output is correct
3 Correct 27 ms 5384 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 3788 KB Output is correct
6 Correct 44 ms 8060 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 31 ms 6652 KB Output is correct
3 Correct 27 ms 5384 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 3788 KB Output is correct
6 Correct 44 ms 8060 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 70 ms 7724 KB Output is correct
9 Correct 61 ms 9124 KB Output is correct
10 Correct 95 ms 11832 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 31 ms 6652 KB Output is correct
3 Correct 27 ms 5384 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 3788 KB Output is correct
6 Correct 44 ms 8060 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 70 ms 7724 KB Output is correct
9 Correct 61 ms 9124 KB Output is correct
10 Correct 95 ms 11832 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 126 ms 11744 KB Output is correct
15 Correct 56 ms 6304 KB Output is correct
16 Correct 96 ms 9412 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 100 ms 11364 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 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 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 204 KB Output is partially correct
2 Correct 77 ms 5052 KB Output is correct
3 Partially correct 125 ms 7456 KB Output is partially correct
4 Partially correct 99 ms 7972 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 204 KB Output is partially correct
2 Correct 77 ms 5052 KB Output is correct
3 Partially correct 125 ms 7456 KB Output is partially correct
4 Partially correct 99 ms 7972 KB Output is partially correct
5 Partially correct 126 ms 8760 KB Output is partially correct
6 Partially correct 126 ms 8580 KB Output is partially correct
7 Partially correct 106 ms 8448 KB Output is partially correct
8 Partially correct 108 ms 8176 KB Output is partially correct
9 Partially correct 89 ms 7452 KB Output is partially correct
10 Partially correct 104 ms 8048 KB Output is partially correct
11 Partially correct 111 ms 8080 KB Output is partially correct
12 Partially correct 97 ms 7440 KB Output is partially correct
13 Correct 58 ms 5720 KB Output is correct
14 Partially correct 98 ms 7900 KB Output is partially correct
15 Partially correct 106 ms 8072 KB Output is partially correct
16 Partially correct 4 ms 588 KB Output is partially correct
17 Correct 54 ms 5328 KB Output is correct
18 Correct 62 ms 5264 KB Output is correct
19 Partially correct 96 ms 7484 KB Output is partially correct
20 Partially correct 110 ms 8084 KB Output is partially correct
21 Partially correct 102 ms 8052 KB Output is partially correct
22 Partially correct 102 ms 8100 KB Output is partially correct