#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()));
} else {
for(j = 0; j < t; j++)
if(K&(1<<j)) WriteAdvice(1);
else WriteAdvice(0);
}
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];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2952 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
4280 KB |
Output is correct |
2 |
Correct |
144 ms |
10724 KB |
Output is correct |
3 |
Correct |
350 ms |
21972 KB |
Output is correct |
4 |
Correct |
159 ms |
14360 KB |
Output is correct |
5 |
Correct |
226 ms |
16800 KB |
Output is correct |
6 |
Correct |
291 ms |
18820 KB |
Output is correct |
7 |
Correct |
339 ms |
20880 KB |
Output is correct |
8 |
Correct |
284 ms |
18308 KB |
Output is correct |
9 |
Correct |
115 ms |
13560 KB |
Output is correct |
10 |
Correct |
345 ms |
21224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
16536 KB |
Output is correct |
2 |
Correct |
352 ms |
20860 KB |
Output is correct |
3 |
Correct |
343 ms |
20964 KB |
Output is correct |
4 |
Correct |
339 ms |
20964 KB |
Output is correct |
5 |
Correct |
334 ms |
20704 KB |
Output is correct |
6 |
Correct |
343 ms |
21140 KB |
Output is correct |
7 |
Correct |
344 ms |
20980 KB |
Output is correct |
8 |
Correct |
347 ms |
21088 KB |
Output is correct |
9 |
Correct |
328 ms |
21324 KB |
Output is correct |
10 |
Correct |
344 ms |
21340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
3260 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
338 ms |
19520 KB |
Output is partially correct - 1500000 bits used |
2 |
Correct |
341 ms |
19724 KB |
Output is partially correct - 1500000 bits used |
3 |
Correct |
352 ms |
19844 KB |
Output is partially correct - 1500000 bits used |
4 |
Correct |
346 ms |
20044 KB |
Output is partially correct - 1500000 bits used |
5 |
Correct |
343 ms |
19836 KB |
Output is partially correct - 1500000 bits used |
6 |
Correct |
360 ms |
19948 KB |
Output is partially correct - 1500000 bits used |
7 |
Correct |
348 ms |
19872 KB |
Output is partially correct - 1497585 bits used |
8 |
Correct |
348 ms |
19976 KB |
Output is partially correct - 1500000 bits used |
9 |
Correct |
340 ms |
19924 KB |
Output is partially correct - 1500000 bits used |
10 |
Correct |
336 ms |
19812 KB |
Output is partially correct - 1500000 bits used |