#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void ComputeAdvice(int *c, int n, int k, int m) {
vector<queue<int>> nextocc(n);
for (int i = 0; i<n; i++){
nextocc[c[i]].push(i);
}
int bitwidth = ceil(log2(k));
set<pair<int,int>> scaffrem;
pbds_set<int> scaff;
for (int i = 0; i<k; i++){
if (nextocc[i].size()>0){
scaffrem.insert({nextocc[i].front(),i});
} else {
scaffrem.insert({n,i});
}
scaff.insert(i);
}
for (int i = 0; i<n; i++){
//cout<<i<<'\n';
if (scaff.find(c[i])!=scaff.end()){
scaffrem.erase({nextocc[c[i]].front(),c[i]});
} else {
//check if the one we just put on can be removed
auto toremove = prev(scaffrem.end());
int ind;
if (i>0&&nextocc[c[i-1]].size()==0&&c[i]!=c[i-1]){
//cout<<"remove\n";
WriteAdvice(1);
toremove = scaffrem.find({n,c[i-1]});
ind = scaff.order_of_key(toremove->second);
} else {
//cout<<"take\n";
//can we get rid of one we've already used
/*auto it = scaffrem.lower_bound({i,-1});
if (it!=scaffrem.begin()){
toremove = prev(it);
}*/
//transmit ind
ind = scaff.order_of_key(toremove->second);
if (toremove->second==c[i-1]){
WriteAdvice(1);
} else {
WriteAdvice(0);
for (int i = bitwidth-1; i>=0; i--){
WriteAdvice(bool((1<<i)&ind));
}
}
}
scaffrem.erase(toremove);
scaff.erase(scaff.find_by_order(ind));
scaff.insert(c[i]);
}
int newind = n;
nextocc[c[i]].pop();
if (nextocc[c[i]].size()>0){
newind=nextocc[c[i]].front();
}
scaffrem.insert({newind,c[i]});
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void Assist(unsigned char *A, int n, int k, int r) {
//GetRequest()
//PutBack()
int ptr = 0;
int bitwidth = ceil(log2(k));
pbds_set<int> scaff;
for (int i = 0; i<k; i++){
scaff.insert(i);
}
int prevcol = -1;
for (int i = 0; i<n; i++){
int col = GetRequest();
if (scaff.find(col)!=scaff.end()){
prevcol=col;
continue;
} else {
int removeLast = A[ptr];
//cout<<ptr<<" "<<int(A[ptr])<<'\n';
ptr++;
auto putel = scaff.begin();
if (removeLast){
putel = scaff.find(prevcol);
} else {
int ind = 0;
for (int i = 0; i<bitwidth; i++){
ind*=2;
ind+=A[ptr];
ptr++;
}
//cout<<ind<<'\n';
putel = scaff.find_by_order(ind);
}
//cout<<"put back "<<*putel<<'\n';
PutBack(*putel);
scaff.erase(putel);
scaff.insert(col);
}
prevcol=col;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
780 KB |
Output is correct |
2 |
Correct |
1 ms |
968 KB |
Output is correct |
3 |
Correct |
3 ms |
2048 KB |
Output is correct |
4 |
Correct |
6 ms |
4608 KB |
Output is correct |
5 |
Incorrect |
6 ms |
7424 KB |
Error - Not putting back color when it is not on the scaffold |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
14592 KB |
Output is correct |
2 |
Correct |
135 ms |
70440 KB |
Output is correct |
3 |
Correct |
348 ms |
144368 KB |
Output is correct |
4 |
Correct |
185 ms |
137568 KB |
Output is correct |
5 |
Correct |
242 ms |
137880 KB |
Output is correct |
6 |
Correct |
300 ms |
138992 KB |
Output is correct |
7 |
Correct |
336 ms |
141560 KB |
Output is correct |
8 |
Correct |
271 ms |
121328 KB |
Output is correct |
9 |
Correct |
160 ms |
135152 KB |
Output is correct |
10 |
Correct |
350 ms |
143600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
114680 KB |
Output is correct |
2 |
Correct |
338 ms |
142320 KB |
Output is correct |
3 |
Correct |
364 ms |
142576 KB |
Output is correct |
4 |
Correct |
387 ms |
142576 KB |
Output is correct |
5 |
Correct |
326 ms |
140272 KB |
Output is correct |
6 |
Correct |
336 ms |
142832 KB |
Output is correct |
7 |
Correct |
354 ms |
142560 KB |
Output is correct |
8 |
Correct |
312 ms |
142064 KB |
Output is correct |
9 |
Correct |
289 ms |
142576 KB |
Output is correct |
10 |
Correct |
343 ms |
142576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
6400 KB |
Output is correct |
2 |
Correct |
11 ms |
7680 KB |
Output is correct |
3 |
Correct |
11 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Incorrect |
5 ms |
7424 KB |
Error - advice is too long |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
141808 KB |
Output is partially correct - 368591 bits used |
2 |
Correct |
346 ms |
142320 KB |
Output is partially correct - 359913 bits used |
3 |
Correct |
347 ms |
142576 KB |
Output is partially correct - 344933 bits used |
4 |
Correct |
347 ms |
142576 KB |
Output is partially correct - 344437 bits used |
5 |
Correct |
370 ms |
142576 KB |
Output is partially correct - 344434 bits used |
6 |
Correct |
374 ms |
142576 KB |
Output is partially correct - 344552 bits used |
7 |
Correct |
374 ms |
142320 KB |
Output is partially correct - 344586 bits used |
8 |
Correct |
337 ms |
142832 KB |
Output is partially correct - 344286 bits used |
9 |
Correct |
356 ms |
142576 KB |
Output is partially correct - 343832 bits used |
10 |
Correct |
310 ms |
142320 KB |
Output is correct - 82503 bits used |