답안 #394105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394105 2021-04-25T15:13:28 Z rainboy 최후의 만찬 (IOI12_supper) C
0 / 100
83 ms 6696 KB
#include "advisor.h"
#include <string.h>

#define N	100000

int ii[N], iq[1 + N], pq[N], cnt;

int lt(int i, int j) { return ii[i] > ii[j]; }

int p2(int p) {
	return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}

void pq_up(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_dn(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_add(int i) {
	pq[i] = ++cnt, pq_up(i);
}

int pq_remove_first() {
	int i = iq[1], j = iq[cnt--];

	if (j != i)
		pq[j] = 1, pq_dn(j);
	pq[i] = 0;
	return i;
}

void ComputeAdvice(int *aa, int n, int k, int m) {
	static int qq[N], next[N], pp[N];
	static char used[N], del[N + N];
	int h, i, a;

	for (a = 0; a < n; a++)
		next[a] = n;
	for (i = n - 1; i >= 0; i--) {
		qq[i] = next[aa[i]];
		next[aa[i]] = i;
	}
	for (a = 0; a < k; a++)
		iq[pq[a] = ++cnt] = a, pp[a] = -a - 1, ii[a] = next[a];
	for (h = cnt / 2; h > 0; h--)
		pq_dn(iq[h]);
	memset(used, 1, k * sizeof *used);
	for (i = 0; i < n; i++)
		if (used[aa[i]])
			ii[aa[i]] = qq[i], pq_up(aa[i]);
		else {
			a = pq_remove_first(), used[a] = 0, del[pp[a] + k] = 1;
			a = aa[i], pp[a] = ii[a], ii[a] = qq[i], pq_add(a), used[a] = 1;
		}
	for (i = 0; i < k + n; i++)
		WriteAdvice(del[i]);
}
#include "assistant.h"

#define N	100000

void Assist(unsigned char *cc, int n, int k, int r) {
	static int aa[N];
	static char used[N];
	int i, j;

	for (j = 0, i = 0; j < n; j++) {
		aa[j] = GetRequest();
		if (!used[aa[j]]) {
			int a;

			while (!cc[i])
				i++;
			a = i < k ? k - 1 - i : aa[i - k], i++;
			PutBack(a), used[a] = 0;
			used[aa[j]] = 1;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 436 KB Error - Putting back a color when it is already on the scaffold
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1136 KB Error - Putting back a color when it is already on the scaffold
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 5352 KB Error - Putting back a color when it is already on the scaffold
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 796 KB Error - Putting back a color when it is already on the scaffold
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 6584 KB Error - Putting back a color when it is already on the scaffold
2 Incorrect 76 ms 6696 KB Error - Putting back a color when it is already on the scaffold
3 Incorrect 75 ms 6628 KB Error - Putting back a color when it is already on the scaffold
4 Incorrect 83 ms 6580 KB Error - Putting back a color when it is already on the scaffold
5 Incorrect 83 ms 6592 KB Error - Putting back a color when it is already on the scaffold
6 Incorrect 74 ms 6588 KB Error - Putting back a color when it is already on the scaffold
7 Incorrect 74 ms 6512 KB Error - Putting back a color when it is already on the scaffold
8 Incorrect 76 ms 6620 KB Error - Putting back a color when it is already on the scaffold
9 Incorrect 76 ms 6600 KB Error - Putting back a color when it is already on the scaffold
10 Incorrect 68 ms 6600 KB Error - Putting back a color when it is already on the scaffold