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;
#define v vector
#define ii pair<int,int>
#define fi first
#define se second
void ComputeAdvice(int *C, int N, int K, int M) {
int sik = 0;
for(int i=0; i<32; i++){
if(K & (1<<i)) sik = i+1;
}
v<int> lastpos(N,N+1);
v<int> nextpos(N);
v<int> nextposk(K,N+1);
for(int i=N-1; i>=0; i--){
if(C[i]<K) nextposk[C[i]] = i;
nextpos[i] = lastpos[C[i]];
lastpos[C[i]] = i;
}
v<int> scaff(N,-1);
priority_queue<ii> pq;
for(int i=0; i<K; i++){
scaff[i]=i;
pq.push({nextposk[i], i});
}
for(int i=0; i<N; i++){
int req = C[i];
if(scaff[req]==-1){
int rem = pq.top().se;
pq.pop();
int k = scaff[rem];
scaff[req] = k;
pq.push({nextpos[i], req});
scaff[rem] = -1;
for(int b=0; b<sik; b++) WriteAdvice((bool)(k & (1<<b)));
} else{
pq.push({nextpos[i], req});
}
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
#define v vector
#define ii pair<int,int>
#define fi first
#define se second
void Assist(unsigned char *A, int N, int K, int R) {
int sik = 0;
for(int i=0; i<32; i++){
if(K & (1<<i)) sik = i+1;
}
v<int> scaff(N, -1);
v<int> revscaff(K, -1);
for(int i=0; i<K; i++){
scaff[i]=i;
revscaff[i]=i;
}
int aind=0;
for(int i=0; i<N; i++){
int req = GetRequest();
if(scaff[req]==-1){
int k=0;
for(int j=0; j<sik; j++){
if(A[aind]==1) k |= (1<<j);
aind++;
}
int rem = revscaff[k];
PutBack(rem);
scaff[rem]=-1;
scaff[req]=k;
revscaff[k]=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... |