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"
using namespace std;
void ComputeAdvice(int *C, int n, int k, int m) {
int inf = 2*n;
set<int> cur;
set<pair<int, int>> pri;
vector<set<int>> nxt(n);
for(int i = 0; i < n; ++i){
nxt[C[i]].insert(i);
}
for(int i = 0; i < n; ++i){
nxt[i].insert(inf);
}
for(int i = 0; i < k; ++i){
cur.insert(i);
pri.insert({-*nxt[i].begin(),i});
}
vector<int> rem(n);
for(int i = 0; i < n; ++i){
/*for(auto[x, y] : pri)
printf("%i %i", x, y);
printf("\n");*/
int c = C[i];
if(cur.find(c) != cur.end()){
rem[i] = -1;
pri.erase({-*nxt[c].begin(),c});
nxt[c].erase(nxt[c].begin());
pri.insert({-*nxt[c].begin(),c});
}else{
auto[x, cr] = *pri.begin();
rem[i] = cr;
pri.erase(pri.begin());
cur.erase(cr);
nxt[c].erase(nxt[c].begin());
pri.insert({-*nxt[c].begin(),c});
cur.insert(c);
}
}
/*for(int r : rem)
printf("%i ", r);
printf("\n");*/
vector<int> lst(n, -1);
vector<unsigned char> sol(n+k, 0);
for(int i = 0; i < k; ++i){
lst[i] = i;
}
for(int i = 0; i < n; ++i){
int c = C[i];
int r = rem[i];
if(r == -1){
sol[lst[c]] = 1;
}else{
sol[lst[r]] = 0;
}
lst[c] = i+k;
}
for(unsigned char bit : sol){
WriteAdvice(bit);
}
/*for(unsigned char c : sol)
printf("%i", c);
printf("\n");*/
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
void Assist(unsigned char *A, int n, int k, int r) {
int i;
set<pair<unsigned char, int>> shelf;
for(i = 0; i < k; i++){
shelf.insert({A[i], i});
}
for (i = 0; i < n; i++) {
int c = GetRequest();
if(shelf.find({1, c}) != shelf.end()){
shelf.erase({1, c});
shelf.insert({A[i+k], c});
continue;
}
PutBack(shelf.begin()->second);
shelf.erase(shelf.begin());
shelf.insert({A[i+k], c});
}
}
# | 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... |