Submission #394107

# Submission time Handle Problem Language Result Execution time Memory
394107 2021-04-25T15:24:48 Z rainboy Last supper (IOI12_supper) C
0 / 100
89 ms 5816 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] = ii[a], 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] = 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"
#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;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 500 KB Output is correct
2 Incorrect 1 ms 500 KB Error - Putting back a color that is not on the scaffold
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1084 KB Error - Putting back a color that is not on the scaffold
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 4712 KB Error - Putting back a color that is not on the scaffold
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 780 KB Error - Putting back a color that is not on the scaffold
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 5592 KB Error - Putting back a color that is not on the scaffold
2 Incorrect 89 ms 5644 KB Error - Putting back a color that is not on the scaffold
3 Incorrect 79 ms 5816 KB Error - Putting back a color that is not on the scaffold
4 Incorrect 79 ms 5728 KB Error - Putting back a color that is not on the scaffold
5 Incorrect 79 ms 5684 KB Error - Putting back a color that is not on the scaffold
6 Incorrect 76 ms 5704 KB Error - Putting back a color that is not on the scaffold
7 Incorrect 76 ms 5696 KB Error - Putting back a color that is not on the scaffold
8 Incorrect 74 ms 5652 KB Error - Putting back a color that is not on the scaffold
9 Incorrect 80 ms 5732 KB Error - Putting back a color that is not on the scaffold
10 Incorrect 73 ms 5600 KB Error - Putting back a color that is not on the scaffold