답안 #394110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394110 2021-04-25T15:31:15 Z rainboy 최후의 만찬 (IOI12_supper) C
100 / 100
95 ms 6140 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]])
			a = aa[i], pp[a] = i, ii[a] = qq[i], pq_up(a);
		else {
			a = pq_remove_first(), used[a] = 0, del[pp[a] + k] = 1;
			a = aa[i], pp[a] = i, ii[a] = qq[i], pq_add(a), used[a] = 1;
		}
	for (i = 0; i < k + n; i++)
		WriteAdvice(del[i]);
}
#include "assistant.h"
#include <string.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, a;

	memset(used, 1, k * sizeof *used);
	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;
		}
	}
}

Compilation message

assistant.c: In function 'Assist':
assistant.c:9:12: warning: unused variable 'a' [-Wunused-variable]
    9 |  int i, j, a;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 492 KB Output is correct
2 Correct 0 ms 492 KB Output is correct
3 Correct 2 ms 624 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 5 ms 888 KB Output is correct
6 Correct 5 ms 908 KB Output is correct
7 Correct 4 ms 908 KB Output is correct
8 Correct 4 ms 916 KB Output is correct
9 Correct 5 ms 916 KB Output is correct
10 Correct 5 ms 912 KB Output is correct
11 Correct 5 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1144 KB Output is correct
2 Correct 40 ms 3296 KB Output is correct
3 Correct 83 ms 6120 KB Output is correct
4 Correct 78 ms 5820 KB Output is correct
5 Correct 75 ms 5784 KB Output is correct
6 Correct 75 ms 5820 KB Output is correct
7 Correct 83 ms 5916 KB Output is correct
8 Correct 61 ms 5096 KB Output is correct
9 Correct 67 ms 5696 KB Output is correct
10 Correct 78 ms 6116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4928 KB Output is correct
2 Correct 79 ms 6128 KB Output is correct
3 Correct 80 ms 6008 KB Output is correct
4 Correct 81 ms 6056 KB Output is correct
5 Correct 76 ms 5908 KB Output is correct
6 Correct 77 ms 6116 KB Output is correct
7 Correct 79 ms 6140 KB Output is correct
8 Correct 71 ms 6020 KB Output is correct
9 Correct 78 ms 5940 KB Output is correct
10 Correct 77 ms 6116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 904 KB Output is correct
2 Correct 5 ms 908 KB Output is correct
3 Correct 5 ms 908 KB Output is correct
4 Correct 4 ms 912 KB Output is correct
5 Correct 4 ms 916 KB Output is correct
6 Correct 5 ms 908 KB Output is correct
7 Correct 5 ms 928 KB Output is correct
8 Correct 5 ms 912 KB Output is correct
9 Correct 5 ms 924 KB Output is correct
10 Correct 5 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 6040 KB Output is correct - 120000 bits used
2 Correct 80 ms 5996 KB Output is correct - 122000 bits used
3 Correct 80 ms 6080 KB Output is correct - 125000 bits used
4 Correct 95 ms 6028 KB Output is correct - 125000 bits used
5 Correct 77 ms 6008 KB Output is correct - 125000 bits used
6 Correct 91 ms 6040 KB Output is correct - 125000 bits used
7 Correct 77 ms 6028 KB Output is correct - 124828 bits used
8 Correct 80 ms 6128 KB Output is correct - 124910 bits used
9 Correct 86 ms 6044 KB Output is correct - 125000 bits used
10 Correct 75 ms 6012 KB Output is correct - 125000 bits used