#include "advisor.h"
#include <stdio.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;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
628 KB |
Output is correct |
4 |
Correct |
4 ms |
648 KB |
Output is correct |
5 |
Correct |
4 ms |
944 KB |
Output is correct |
6 |
Correct |
5 ms |
932 KB |
Output is correct |
7 |
Correct |
5 ms |
928 KB |
Output is correct |
8 |
Correct |
5 ms |
932 KB |
Output is correct |
9 |
Correct |
5 ms |
940 KB |
Output is correct |
10 |
Correct |
5 ms |
912 KB |
Output is correct |
11 |
Correct |
5 ms |
932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1084 KB |
Output is correct |
2 |
Correct |
38 ms |
3916 KB |
Output is correct |
3 |
Correct |
79 ms |
7288 KB |
Output is correct |
4 |
Correct |
73 ms |
6996 KB |
Output is correct |
5 |
Correct |
75 ms |
7016 KB |
Output is correct |
6 |
Correct |
79 ms |
7152 KB |
Output is correct |
7 |
Correct |
81 ms |
7300 KB |
Output is correct |
8 |
Correct |
68 ms |
6284 KB |
Output is correct |
9 |
Correct |
66 ms |
6932 KB |
Output is correct |
10 |
Correct |
78 ms |
7292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
4892 KB |
Output is correct |
2 |
Correct |
80 ms |
7208 KB |
Output is correct |
3 |
Correct |
78 ms |
7200 KB |
Output is correct |
4 |
Correct |
78 ms |
7156 KB |
Output is correct |
5 |
Correct |
75 ms |
7180 KB |
Output is correct |
6 |
Correct |
79 ms |
7180 KB |
Output is correct |
7 |
Correct |
81 ms |
7168 KB |
Output is correct |
8 |
Correct |
73 ms |
7256 KB |
Output is correct |
9 |
Correct |
76 ms |
7200 KB |
Output is correct |
10 |
Correct |
87 ms |
7220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
784 KB |
Output is correct |
2 |
Correct |
6 ms |
912 KB |
Output is correct |
3 |
Correct |
5 ms |
916 KB |
Output is correct |
4 |
Correct |
3 ms |
936 KB |
Output is correct |
5 |
Correct |
5 ms |
936 KB |
Output is correct |
6 |
Correct |
5 ms |
932 KB |
Output is correct |
7 |
Correct |
5 ms |
936 KB |
Output is correct |
8 |
Correct |
5 ms |
944 KB |
Output is correct |
9 |
Correct |
5 ms |
936 KB |
Output is correct |
10 |
Correct |
5 ms |
944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
5952 KB |
Output is correct - 120000 bits used |
2 |
Correct |
78 ms |
5988 KB |
Output is correct - 122000 bits used |
3 |
Correct |
78 ms |
6100 KB |
Output is correct - 125000 bits used |
4 |
Correct |
78 ms |
6012 KB |
Output is correct - 125000 bits used |
5 |
Correct |
81 ms |
6168 KB |
Output is correct - 125000 bits used |
6 |
Correct |
78 ms |
6128 KB |
Output is correct - 125000 bits used |
7 |
Correct |
89 ms |
6092 KB |
Output is correct - 124828 bits used |
8 |
Correct |
80 ms |
5996 KB |
Output is correct - 124910 bits used |
9 |
Correct |
78 ms |
6048 KB |
Output is correct - 125000 bits used |
10 |
Correct |
72 ms |
6168 KB |
Output is correct - 125000 bits used |