#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]])
print(n, l), ii[aa[i]] = qq[i], pq_dn(aa[i]);
else {
int a;
a = pq_remove_first(), print(a, l), used[a] = 0;
ii[aa[i]] = qq[i], pq_add(aa[i]), used[aa[i]] = 1;
}
}
#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[i * l + 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 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
500 KB |
Output is correct |
2 |
Incorrect |
2 ms |
488 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
1844 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
347 ms |
11616 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
620 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
445 ms |
14640 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
449 ms |
14472 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
436 ms |
14440 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
452 ms |
14444 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
466 ms |
14428 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
431 ms |
14392 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
455 ms |
14596 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
436 ms |
14384 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
431 ms |
14492 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
460 ms |
14508 KB |
Output isn't correct - not an optimal way |