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 <bits/stdc++.h>
#include "advisor.h"
//~ #include "grader.cpp"
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M) {
vector <int> las(N, N);
vector <int> nex(N);
for(int i = N - 1 ; i >= 0 ; i--){
nex[i] = las[C[i]];
las[C[i]] = i;
}
set <pair <int, int> > ready;
for(int i = 0 ; i < K ; i++){
ready.insert(make_pair(las[i], i));
}
vector <int> p(N);
for(int i = 0 ; i < N ; i++){
if(ready.count(make_pair(i, C[i]))){
ready.erase(ready.find(make_pair(i, C[i])));
ready.insert(make_pair(nex[i], C[i]));
continue;
}
ready.erase(--ready.end());
ready.insert(make_pair(nex[i], C[i]));
p[i] = 1;
}
for(int i = 0 ; i < K ; i++){
if(las[i] == N) WriteAdvice(1);
else WriteAdvice(p[las[i]]);
}
for(int i = 0 ; i < N ; i++){
if(nex[i] == N) WriteAdvice(1);
else WriteAdvice(p[nex[i]]);
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
set <int> ready, passive;
for(int i = 0 ; i < K ; i++){
if(A[i] == 1) passive.insert(i);
ready.insert(i);
}
for(int i = 0 ; i < N ; i++){
int x = GetRequest();
if(ready.count(x) == 0){
int put = -1;
for(auto &j : passive){
if(ready.count(j)){
put = j;
break;
}
}
assert(put != -1);
PutBack(put);
ready.erase(put);
ready.insert(x);
}
if(A[K + i] == 1) passive.insert(x);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |