#include "advisor.h"
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#include <stdio.h>
using namespace std;
int where[1000005];
int Next[1000005];
vector < int > when[100005];
map < int , int > how;
void ComputeAdvice(int *C, int N, int K, int M)
{
int t=0,now=1,xx,i,j;
while(now<K)
{
now*=2;
t++;
}
for(i=0;i<N;i++) when[C[i]].push_back(i);
for(i=0;i<N;i++) when[i].push_back(i+N);
for(i=0;i<N;i++) Next[i]=*upper_bound(when[C[i]].begin(),when[C[i]].end(),i);
for(i=0;i<K;i++)
{
where[i]=i;
how[when[i][0]]=i;
}
for(i=K;i<N;i++) where[i]=-1;
for(i=0;i<N;i++)
{
if(how.find(i)!=how.end()) how.erase(i);
if(where[C[i]]==-1)
{
xx=where[prev(how.end())->second];
for(j=0;j<t;j++)
{
if(xx&(1<<j)) WriteAdvice(1);
else WriteAdvice(0);
}
where[C[i]]=xx;
where[prev(how.end())->second]=-1;
how.erase(prev(how.end()));
}
how[Next[i]]=C[i];
}
}
#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];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2960 KB |
Error - Not putting back color when it is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
4132 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
167 ms |
14332 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
3080 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
208 ms |
17276 KB |
Execution killed with signal 11 |
2 |
Runtime error |
211 ms |
17160 KB |
Execution killed with signal 11 |
3 |
Runtime error |
206 ms |
17184 KB |
Execution killed with signal 11 |
4 |
Runtime error |
196 ms |
17156 KB |
Execution killed with signal 11 |
5 |
Runtime error |
198 ms |
17204 KB |
Execution killed with signal 11 |
6 |
Runtime error |
202 ms |
17292 KB |
Execution killed with signal 11 |
7 |
Runtime error |
204 ms |
17148 KB |
Execution killed with signal 11 |
8 |
Runtime error |
199 ms |
17156 KB |
Execution killed with signal 11 |
9 |
Runtime error |
193 ms |
17224 KB |
Execution killed with signal 11 |
10 |
Runtime error |
264 ms |
20264 KB |
Execution killed with signal 11 |