#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);
}
int 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;
}
int 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 print(int a, int l) {
int h;
for (h = 0; h < l; h++)
WriteAdvice(a >> h & 1);
}
void ComputeAdvice(int *aa, int n, int k, int m) {
static int qq[N], next[N];
static char used[N];
int l, 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, ii[a] = next[a];
for (h = cnt / 2; h > 0; h--)
pq_dn(iq[h]);
memset(used, 1, k * sizeof *used);
l = 0;
while (1 << l < n + 1)
l++;
for (i = 0; i < n; i++)
if (used[aa[i]]) {
ii[aa[i]] = qq[i], pq_dn(aa[i]);
print(n, l);
} else {
int a;
used[aa[i]] = 1;
a = pq_remove_first(), print(a, l);
ii[aa[i]] = qq[i], pq_add(aa[i]);
}
}
#include "assistant.h"
void Assist(unsigned char *cc, int n, int k, int r) {
int i, l;
l = 0;
while (1 << l < n + 1)
l++;
for (i = 0; i < n; i++) {
int h, a;
GetRequest();
a = 0;
for (h = 0; h < l; h++)
if (cc[h])
a |= 1 << h;
if (a != n)
PutBack(a);
}
}
Compilation message
advisor.c: In function 'pq_up':
advisor.c:20:1: warning: control reaches end of non-void function [-Wreturn-type]
20 | }
| ^
advisor.c: In function 'pq_dn':
advisor.c:28:1: warning: control reaches end of non-void function [-Wreturn-type]
28 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
492 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
1836 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 |
335 ms |
11948 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 |
1 ms |
632 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
417 ms |
14612 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Incorrect |
426 ms |
14900 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Incorrect |
461 ms |
14640 KB |
Error - Not putting back color when it is not on the scaffold |
4 |
Incorrect |
414 ms |
14588 KB |
Error - Not putting back color when it is not on the scaffold |
5 |
Incorrect |
419 ms |
14652 KB |
Error - Putting back a color that is not on the scaffold |
6 |
Incorrect |
416 ms |
14652 KB |
Error - Putting back a color that is not on the scaffold |
7 |
Incorrect |
419 ms |
14752 KB |
Error - Putting back a color when it is already on the scaffold |
8 |
Incorrect |
424 ms |
14748 KB |
Error - Putting back a color that is not on the scaffold |
9 |
Incorrect |
424 ms |
14640 KB |
Error - Not putting back color when it is not on the scaffold |
10 |
Incorrect |
450 ms |
14620 KB |
Error - Putting back a color that is not on the scaffold |