#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M) {
int res[N], last[N], nxt[N], s[K];
iota(s, s+K, 0);
priority_queue<pair<int, int>> q;
memset(last, 1, sizeof last);
for(int i = N; i--;)
nxt[i] = last[C[i]], last[C[i]] = i;
bool on[N];
memset(on, 0, sizeof on);
for(int i = 0; i < K; i++)
q.push({last[i], i}), on[i] = 1;
for(int i = 0; i < N; i++) {
int col = C[i];
if(!on[col]) {
int x = q.top().second;
on[x] = 0;
for(int j = 0; j < K; j++) if(s[j]==x) res[i] = j, s[j] = col;
q.pop();
q.push({nxt[i], col});
on[col] = 1;
} else res[i] = K;
}
int bits = log2(K)+1;
for(int i = 0; i < N; i++)
for(int j = 0; j < bits; j++)
WriteAdvice(res[i]&1<<j);
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
priority_queue<pair<int, int>> q;
int last[N], nxt[N];
memset(last, 1, sizeof last);
int C[N], bits = log2(K)+1;
memset(C, 0, sizeof C);
for(int i = 0; i < N; i++)
for(int j = 0; j < bits; j++)
C[i]|=(int)A[i*bits+j] << j;
int scaffold[K];
iota(scaffold, scaffold+K, 0);
for(int i = 0; i < N; i++) {
int x = GetRequest();
if(C[i]<K)
PutBack(scaffold[C[i]]), scaffold[C[i]] = x;
}
}
Compilation message
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:8:16: warning: unused variable 'nxt' [-Wunused-variable]
8 | int last[N], nxt[N];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
520 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
852 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
738 ms |
2584 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
632 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
953 ms |
2904 KB |
Error - advice must be 0 or 1 |
2 |
Incorrect |
976 ms |
2960 KB |
Error - advice must be 0 or 1 |
3 |
Incorrect |
1033 ms |
2984 KB |
Error - advice must be 0 or 1 |
4 |
Incorrect |
1094 ms |
2868 KB |
Error - advice must be 0 or 1 |
5 |
Incorrect |
1035 ms |
2856 KB |
Error - advice must be 0 or 1 |
6 |
Incorrect |
1028 ms |
2900 KB |
Error - advice must be 0 or 1 |
7 |
Incorrect |
1038 ms |
2916 KB |
Error - advice must be 0 or 1 |
8 |
Incorrect |
1044 ms |
2924 KB |
Error - advice must be 0 or 1 |
9 |
Incorrect |
1061 ms |
2916 KB |
Error - advice must be 0 or 1 |
10 |
Incorrect |
1348 ms |
2880 KB |
Error - advice must be 0 or 1 |