#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]])
ii[aa[i]] = qq[i], pq_up(aa[i]);
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;
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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
504 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1088 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
4660 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
648 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
82 ms |
5596 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Incorrect |
76 ms |
5508 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Incorrect |
74 ms |
5876 KB |
Error - Putting back a color that is not on the scaffold |
4 |
Incorrect |
76 ms |
5580 KB |
Error - Putting back a color that is not on the scaffold |
5 |
Incorrect |
75 ms |
5596 KB |
Error - Putting back a color that is not on the scaffold |
6 |
Incorrect |
79 ms |
5564 KB |
Error - Putting back a color that is not on the scaffold |
7 |
Incorrect |
82 ms |
5576 KB |
Error - Putting back a color that is not on the scaffold |
8 |
Incorrect |
77 ms |
5592 KB |
Error - Putting back a color that is not on the scaffold |
9 |
Incorrect |
74 ms |
5640 KB |
Error - Putting back a color that is not on the scaffold |
10 |
Incorrect |
68 ms |
5624 KB |
Error - Putting back a color that is not on the scaffold |