#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#include "advisor.h"
const int INF = 1e9;
void ComputeAdvice(int *C, int N, int K, int M) {
vector<int> put_down;
vector<vector<int>> oc;
int log2 = 1;
while((1<<log2)<N){
log2++;
}
oc.resize(N);
for(int i = 0; i<N; i++){
oc[C[i]].push_back(i);
}
set<int> zeros;
set<int> ones;
for(int i = 0; i<N; i++){
oc[i].push_back(INF);
reverse(oc[i].begin(), oc[i].end());
if(oc[i].size()==1 || (oc[i].size()==2 && i>=K)){
zeros.insert(i);
}
}
set<pii> cur_colors;
for(int i = 0; i<K; i++){
cur_colors.insert({oc[i].back(), i});
}
for(int i = 0; i<N; i++){
int needed = C[i];
if(cur_colors.find({oc[C[i]].back(), C[i]}) == cur_colors.end()){
pii removing = *(--cur_colors.end());
cur_colors.erase(removing);
if(zeros.find(removing.second) == zeros.end()){
put_down.push_back(removing.second);
}
}
else{
cur_colors.erase({oc[needed].back(), needed});
}
oc[needed].pop_back();
cur_colors.insert({oc[needed].back(), needed});
}
for(int i = 0; i<N; i++){
if(zeros.find(i) == zeros.end()){
WriteAdvice(1);
}
else{
WriteAdvice(0);
}
}
for(auto e: put_down){
for(int i = 0; i<log2; i++){
WriteAdvice((e&(1<<i))>>i);
}
}
}
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#include "assistant.h"
void Assist(unsigned char *A, int N, int K, int R) {
int log2 = 1;
while((1<<log2)<N){
log2++;
}
set<int> cur_colors;
for(int i = 0; i<K; i++){
cur_colors.insert(i);
}
vector<int> put_down;
set<int> zeros;
for(int i = 0; i<N; i++){
int val =A[i];
if(val == 0){
zeros.insert(i);
}
}
for(int i =N; i<R; i+=log2){
int val = 0;
for(int j = 0; j<log2; j++){
val += A[j+i] * (1<<j);
}
put_down.push_back(val);
}
reverse(put_down.begin(), put_down.end());
set<int> zeros_inside;
for(int i = 0; i<K; i++){
if(zeros.find(i)!=zeros.end()){
zeros_inside.insert(i);
}
}
for (int i = 0; i < N; i++) {
int req = GetRequest();
if(zeros_inside.size()>0 && cur_colors.find(req) == cur_colors.end()){
//cout<<*zeros_inside.begin()<<endl;
PutBack(*zeros_inside.begin());
zeros_inside.erase(zeros_inside.begin());
}
else if(cur_colors.find(req) == cur_colors.end()){
//cout<<put_down.back()<<endl;
PutBack(put_down.back());
cur_colors.erase(put_down.back());
put_down.pop_back();
}
if(zeros.find(req) != zeros.end()){
zeros_inside.insert(req);
}
else{
cur_colors.insert(req);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
792 KB |
Output is correct |
2 |
Correct |
1 ms |
788 KB |
Output is correct |
3 |
Correct |
2 ms |
788 KB |
Output is correct |
4 |
Correct |
7 ms |
1628 KB |
Output is correct |
5 |
Correct |
11 ms |
1672 KB |
Output is correct |
6 |
Correct |
10 ms |
1648 KB |
Output is correct |
7 |
Correct |
5 ms |
1592 KB |
Output is correct |
8 |
Correct |
5 ms |
1596 KB |
Output is correct |
9 |
Correct |
11 ms |
1664 KB |
Output is correct |
10 |
Correct |
8 ms |
2000 KB |
Output is correct |
11 |
Correct |
7 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2488 KB |
Output is correct |
2 |
Correct |
114 ms |
10072 KB |
Output is correct |
3 |
Correct |
181 ms |
17940 KB |
Output is correct |
4 |
Correct |
277 ms |
20152 KB |
Output is correct |
5 |
Correct |
260 ms |
19376 KB |
Output is correct |
6 |
Correct |
236 ms |
18344 KB |
Output is correct |
7 |
Correct |
208 ms |
18124 KB |
Output is correct |
8 |
Correct |
119 ms |
14904 KB |
Output is correct |
9 |
Correct |
355 ms |
25788 KB |
Output is correct |
10 |
Correct |
200 ms |
18420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
14608 KB |
Output is correct |
2 |
Correct |
202 ms |
17956 KB |
Output is correct |
3 |
Correct |
221 ms |
18808 KB |
Output is correct |
4 |
Correct |
204 ms |
18432 KB |
Output is correct |
5 |
Correct |
193 ms |
18180 KB |
Output is correct |
6 |
Correct |
201 ms |
18240 KB |
Output is correct |
7 |
Correct |
200 ms |
18460 KB |
Output is correct |
8 |
Correct |
150 ms |
17624 KB |
Output is correct |
9 |
Correct |
161 ms |
18848 KB |
Output is correct |
10 |
Correct |
210 ms |
18508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1304 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
205 ms |
18028 KB |
Output is partially correct - 431670 bits used |
2 |
Correct |
209 ms |
18220 KB |
Output is partially correct - 406391 bits used |
3 |
Correct |
200 ms |
18444 KB |
Output is partially correct - 393046 bits used |
4 |
Correct |
202 ms |
18500 KB |
Output is partially correct - 394100 bits used |
5 |
Correct |
201 ms |
18368 KB |
Output is partially correct - 397687 bits used |
6 |
Correct |
202 ms |
18256 KB |
Output is partially correct - 396004 bits used |
7 |
Correct |
216 ms |
18452 KB |
Output is partially correct - 395605 bits used |
8 |
Correct |
202 ms |
18496 KB |
Output is partially correct - 393335 bits used |
9 |
Correct |
204 ms |
18488 KB |
Output is partially correct - 395375 bits used |
10 |
Correct |
143 ms |
17644 KB |
Output is correct - 132487 bits used |