#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<int> lastocc(n,-1);
for (int i = 0; i<n; i++){
lastocc[c[i]]=i;
}
int bitwidth = ceil(log2(k));
set<pair<int,int>> scaffrem;
pbds_set<int> scaff;
for (int i = 0; i<k; i++){
scaffrem.insert({lastocc[i],i});
scaff.insert(i);
}
for (int i = 0; i<n; i++){
if (scaff.find(c[i])!=scaff.end()){
continue;
} else {
auto toremove = prev(scaffrem.end());
//can we get rid of one we've already used
auto it = scaffrem.lower_bound({i,-1});
if (it!=scaffrem.begin()){
toremove = prev(it);
}
int ind = scaff.order_of_key(toremove->second);
//transmit ind
for (int i = bitwidth-1; i>=0; i--){
WriteAdvice((1<<i)&ind);
}
scaffrem.erase(toremove);
scaff.erase(scaff.find_by_order(ind));
scaffrem.insert({-lastocc[c[i]],c[i]});
scaff.insert(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);
}
for (int i = 0; i<n; i++){
int col = GetRequest();
if (scaff.find(col)!=scaff.end()){
continue;
} else {
int ind = 0;
for (int i = 0; i<bitwidth; i++){
ind*=2;
ind+=A[ptr];
ptr++;
}
auto putel = scaff.find_by_order(ind);
PutBack(*putel);
scaff.erase(putel);
scaff.insert(col);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1028 KB |
Output is correct |
2 |
Incorrect |
0 ms |
776 KB |
Error - advice must be 0 or 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1280 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
6416 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1024 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
7152 KB |
Error - advice must be 0 or 1 |
2 |
Incorrect |
35 ms |
7664 KB |
Error - advice must be 0 or 1 |
3 |
Incorrect |
36 ms |
8176 KB |
Error - advice must be 0 or 1 |
4 |
Incorrect |
35 ms |
8176 KB |
Error - advice must be 0 or 1 |
5 |
Incorrect |
35 ms |
8056 KB |
Error - advice must be 0 or 1 |
6 |
Incorrect |
37 ms |
8176 KB |
Error - advice must be 0 or 1 |
7 |
Incorrect |
35 ms |
8176 KB |
Error - advice must be 0 or 1 |
8 |
Incorrect |
35 ms |
8176 KB |
Error - advice must be 0 or 1 |
9 |
Incorrect |
37 ms |
8176 KB |
Error - advice must be 0 or 1 |
10 |
Incorrect |
45 ms |
8176 KB |
Error - advice must be 0 or 1 |