#pragma once
// #include "grader.h"
#include "advisor.h"
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;
/*
1 8 N≤5000 M=65000bits
2 9 N≤100000 M=2000000bits
3 9 N≤100000 M=1500bits K≤25000
4 35 N≤5000 M=10000bits
5 up to 39 N≤100000 M=1800000bits K≤25000
*/
void ComputeAdvice(int *c, int n, int k, int m)
{
// cout<<"ASD\n";
vector<int> pos[n];
for(int j=0;j<n;j++)
pos[j].push_back(1e9);
for(int i=n-1;i>=0;i--)
pos[c[i]].push_back(i);
set<pair<int,int>> hap;
map<int,int> color_to_index;
for(int i=0;i<k;i++)
{
// cout<<"Hola "<<-pos[i].back()<<' '<<i<<endl;
hap.insert({-pos[i].back(),i});
color_to_index[i]=i;
}
int lg=log2(k);
for(int j=0;j<n;j++)
{
pos[c[j]].pop_back();
if(color_to_index.find(c[j])==color_to_index.end())
{
auto it=*begin(hap);
hap.erase(begin(hap));
// cout<<"Rem "<<-it.first<<' '<<it.second<<" ind ";
int npd=color_to_index[it.second];
// cout<<npd<<endl;
for(int l=lg;l>=0;l--)
{
if(npd&(1ll<<l))
{
WriteAdvice('1');
}
else
{
WriteAdvice('0');
}
}
color_to_index.erase(it.second);
hap.insert({-pos[c[j]].back(),c[j]});
color_to_index[c[j]]=npd;
}
}
}
#pragma once
// #include "grader.h"
#include "assistant.h"
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;
void Assist(unsigned char *a, int n, int k, int r)
{
vector<int> ans;
set<int> hap;
for(int i=0;i<k;i++)
{
hap.insert(i);
ans.push_back(i);
}
int lg=log2(k);
int p=0;
for(int j=0;j<n;j++)
{
int x=GetRequest();
if(hap.find(x)!=hap.end())
continue;
int ind=0;
for(int l=lg;l>=0;l--)
{
ind*=2;
ind+=(a[p]-'0');
p++;
}
PutBack(ans[ind]);
hap.erase(ans[ind]);
hap.insert(x);
ans[ind]=x;
}
}
Compilation message
advisor.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
assistant.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
796 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1624 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
8300 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1060 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
9808 KB |
Error - advice must be 0 or 1 |
2 |
Incorrect |
24 ms |
9736 KB |
Error - advice must be 0 or 1 |
3 |
Incorrect |
24 ms |
10332 KB |
Error - advice must be 0 or 1 |
4 |
Incorrect |
24 ms |
10352 KB |
Error - advice must be 0 or 1 |
5 |
Incorrect |
24 ms |
10212 KB |
Error - advice must be 0 or 1 |
6 |
Incorrect |
24 ms |
10336 KB |
Error - advice must be 0 or 1 |
7 |
Incorrect |
23 ms |
10460 KB |
Error - advice must be 0 or 1 |
8 |
Incorrect |
24 ms |
9980 KB |
Error - advice must be 0 or 1 |
9 |
Incorrect |
23 ms |
10324 KB |
Error - advice must be 0 or 1 |
10 |
Incorrect |
23 ms |
10028 KB |
Error - advice must be 0 or 1 |