# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871630 | Matjaz | Last supper (IOI12_supper) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "advisor.h"
#include<set>
#include<queue>
#include<vector>
using namespace std;
int L;
void writeInt(int x){
for (int i=0;i<L;i++){
WriteAdvice(x % 2);
x /= 2;
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
for (L=0;L<31;L++){
if ((1<<L) > N) break;
}
set<int> scafold;
for (int i=0;i<K;i++) scafold.insert(i);
vector<queue<int> > Q(N);
for (int i=0;i<N;i++) Q[C[i]].push(i);
for (int i=0;i<N;i++){
Q[C[i]].pop();
if (scafold.count(C[i]) > 0) continue;
int besttime = -1;
int bestcolour = -1;
for (set<int>::iterator it = scafold.begin(); it != scafold.end(); it++){
int u = *it;
if (Q[u].empty() || Q[u].front() > besttime){
besttime = Q[u].empty() ? N : Q[u].front();
bestcolour = u;
}
}
writeInt(bestcolour);
scafold.erase(bestcolour);
scafold.insert(C[i]);
}
}