#include "advisor.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
static const int N = 1e5 + 5;
static int t[N];
static void update(int x, int k) {
for(int i = x + 1; i < N; i += i & -i)
t[i] += k;
}
static int query(int x, int ret = 0) {
for(int i = x + 1; i; i -= i & -i)
ret += t[i];
return ret;
}
static queue<int> col[N];
void ComputeAdvice(int *C, int n, int k, int M) {
for(int i = 0; i < n; i++) col[C[i]].emplace(i);
for(int i = 0; i < n; i++) col[i].emplace(1e9);
priority_queue<pii> Q;
for(int i = 0; i < k; i++) update(i, 1), Q.emplace(col[i].front(), i);
for(int i = 0; i < n; i++) {
col[C[i]].pop();
if(query(C[i]) - query(C[i] - 1) == 1) {
for(int j = 0; j < 15; j++) WriteAdvice(0);
Q.emplace(col[C[i]].front(), C[i]);
} else {
pii now = Q.top(); Q.pop();
int idx = query(now.y);
for(int j = 0; j < 15; j++) WriteAdvice(idx >> j & 1);
Q.emplace(col[C[i]].front(), C[i]);
update(now.y, -1), update(C[i], 1);
}
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
static const int N = 1e5 + 5;
static int t[N];
static void update(int x, int k) {
for(int i = x + 1; i < N; i += i & -i)
t[i] += k;
}
static int query(int x, int ret = 0) {
for(int i = x + 1; i; i -= i & -i)
ret += t[i];
return ret;
}
void Assist(unsigned char *A, int n, int k, int R) {
for(int i = 0; i < k; i++) update(i, 1);
for(int i = 0; i < n; i++) {
int now = GetRequest();
if(query(now) - query(now - 1) == 1) continue;
int idx = 0;
for(int j = 15 * i; j < 15 * (i + 1); j++)
if(A[j] == 1) idx += (1 << (j - 15 * i));
int l = 0, r = n - 1;
while(l < r) {
int mid = (l + r) >> 1;
if(query(mid) >= idx) r = mid;
else l = mid + 1;
}
PutBack(r);
update(r, -1), update(now, 1);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
135408 KB |
Output is correct |
2 |
Correct |
53 ms |
135216 KB |
Output is correct |
3 |
Correct |
63 ms |
135416 KB |
Output is correct |
4 |
Correct |
63 ms |
135664 KB |
Output is correct |
5 |
Incorrect |
56 ms |
135672 KB |
Error - advice is too long |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
136688 KB |
Output is correct |
2 |
Correct |
277 ms |
142064 KB |
Output is correct |
3 |
Incorrect |
469 ms |
148536 KB |
Error - Putting back a color that is not on the scaffold |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
144936 KB |
Output is correct |
2 |
Correct |
504 ms |
148424 KB |
Output is correct |
3 |
Correct |
505 ms |
148504 KB |
Output is correct |
4 |
Correct |
480 ms |
148424 KB |
Output is correct |
5 |
Correct |
474 ms |
148400 KB |
Output is correct |
6 |
Correct |
496 ms |
148512 KB |
Output is correct |
7 |
Correct |
479 ms |
148464 KB |
Output is correct |
8 |
Correct |
511 ms |
148432 KB |
Output is correct |
9 |
Correct |
460 ms |
148672 KB |
Output is correct |
10 |
Correct |
509 ms |
148472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
135560 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
147376 KB |
Output is partially correct - 1500000 bits used |
2 |
Correct |
512 ms |
147560 KB |
Output is partially correct - 1500000 bits used |
3 |
Correct |
486 ms |
147232 KB |
Output is partially correct - 1500000 bits used |
4 |
Correct |
573 ms |
147400 KB |
Output is partially correct - 1500000 bits used |
5 |
Correct |
521 ms |
147176 KB |
Output is partially correct - 1500000 bits used |
6 |
Correct |
554 ms |
147392 KB |
Output is partially correct - 1500000 bits used |
7 |
Correct |
527 ms |
147176 KB |
Output is partially correct - 1497585 bits used |
8 |
Correct |
508 ms |
147480 KB |
Output is partially correct - 1500000 bits used |
9 |
Correct |
495 ms |
147296 KB |
Output is partially correct - 1500000 bits used |
10 |
Correct |
560 ms |
147408 KB |
Output is partially correct - 1500000 bits used |