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;
void ComputeAdvice(int *C, int N, int K, int M) {
set<int> scafold;
for (int i=0;i<K;i++) scafold.insert(i);
vector<queue<int> > Q(N);
vector<queue<int> > returns(N);
for (int i=0;i<N;i++) Q[C[i]].push(i);
for (int i=0;i<N;i++) Q[i].push(N);
vector<int> takeback(N, -1);
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;
}
}
scafold.erase(bestcolour);
scafold.insert(C[i]);
returns[bestcolour].push(i);
takeback[i] = bestcolour;
}
for (int i=0;i<K;i++){
if (Q[i].empty()){
WriteAdvice(0);
continue;
}
if (returns[i].empty()){
WriteAdvice(1);
continue;
}
if (Q[i].front() <= returns[i].front()){
WriteAdvice(1);
} else WriteAdvice(0);
}
for (int i=0;i<N;i++){
Q[C[i]].pop();
if (Q[C[i]].empty()){
WriteAdvice(0);
continue;
}
if (returns[C[i]].empty()){
WriteAdvice(1);
continue;
}
if (Q[C[i]].front() <= returns[C[i]].front()){
WriteAdvice(1);
} else WriteAdvice(0);
returns[takeback[i]].pop();
}
}
#include "assistant.h"
#include<queue>
#include<set>
using namespace std;
void Assist(unsigned char *A, int N, int K, int R) {
set<int> expendable,scafold;
for (int i=0;i<K;i++) if (A[i] == 0) expendable.insert(i);
for (int i=0;i<K;i++) scafold.insert(i);
for (int i=0;i<N;i++){
int req = GetRequest();
if (scafold.count(req) > 0){
if (A[K + i] == 0) expendable.insert(req);
continue;
}
PutBack(*expendable.begin());
scafold.erase(*expendable.begin());
expendable.erase(*expendable.begin());
scafold.insert(req);
if (A[K + i] == 0) expendable.insert(req);
}
}
# | 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... |