# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
820042 | annabeth9680 | Last supper (IOI12_supper) | C++17 | 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 <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+20;
vector<int> t[MAXN];
int A[2*MAXN];
void ComputeAdvice(int *C, int N, int K, int M){ //C = color requests; N = length of C; K = number of colors on the scaffold
for(int i = N-1;i >= 0;--i){
t[C[i]].push_back(i); //the "times" color C[i] is needed, sorted in decreasing order
}
set<pair<int,int>> s;
for(int i = 0;i<K;++i){
if(t[i].empty()) s.insert({N,i});
else s.insert({t[i].back(),i});
}
for(int i = 0;i<N;++i){
if(s.begin()->first == i) s.erase(s.begin());
else{
A[prev(s.end())->second] = 1;
s.erase(prev(s.end()));
}
t[C[i]].pop_back();
s.emplace(t[C[i]].empty() ? N : t[C[i]].back(),i+K);
}
for(int i = 0;i<K+N;++i) WriteAdvice(A[i]);
}