#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_up(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 |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
4 ms |
640 KB |
Output is correct |
4 |
Correct |
10 ms |
960 KB |
Output is correct |
5 |
Correct |
18 ms |
1112 KB |
Output is correct |
6 |
Correct |
18 ms |
1088 KB |
Output is correct |
7 |
Correct |
17 ms |
1176 KB |
Output is correct |
8 |
Correct |
17 ms |
1204 KB |
Output is correct |
9 |
Correct |
18 ms |
1232 KB |
Output is correct |
10 |
Correct |
20 ms |
1140 KB |
Output is correct |
11 |
Correct |
17 ms |
1156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
1708 KB |
Output is correct |
2 |
Correct |
211 ms |
7700 KB |
Output is correct |
3 |
Correct |
441 ms |
15768 KB |
Output is correct |
4 |
Correct |
438 ms |
15476 KB |
Output is correct |
5 |
Correct |
482 ms |
15476 KB |
Output is correct |
6 |
Correct |
437 ms |
15536 KB |
Output is correct |
7 |
Correct |
464 ms |
15628 KB |
Output is correct |
8 |
Correct |
366 ms |
13308 KB |
Output is correct |
9 |
Correct |
431 ms |
15268 KB |
Output is correct |
10 |
Correct |
425 ms |
15664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
11672 KB |
Output is correct |
2 |
Incorrect |
39 ms |
5208 KB |
Error - advice is too long |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
620 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
442 ms |
14408 KB |
Output is partially correct - 1700000 bits used |
2 |
Correct |
435 ms |
14452 KB |
Output is partially correct - 1700000 bits used |
3 |
Correct |
438 ms |
14412 KB |
Output is partially correct - 1700000 bits used |
4 |
Correct |
440 ms |
14356 KB |
Output is partially correct - 1700000 bits used |
5 |
Correct |
429 ms |
14544 KB |
Output is partially correct - 1700000 bits used |
6 |
Correct |
439 ms |
14484 KB |
Output is partially correct - 1700000 bits used |
7 |
Correct |
462 ms |
14348 KB |
Output is partially correct - 1697263 bits used |
8 |
Correct |
454 ms |
14396 KB |
Output is partially correct - 1700000 bits used |
9 |
Correct |
441 ms |
14560 KB |
Output is partially correct - 1700000 bits used |
10 |
Correct |
435 ms |
14356 KB |
Output is partially correct - 1700000 bits used |