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 <queue>
using namespace std;
#define MAXN 100005
typedef pair<int,int> pii;
static int C[MAXN];
static int in_scaffold[MAXN],recent[MAXN],next_[MAXN],first_active[MAXN],request_active[MAXN],request_num[MAXN];
static priority_queue<pii> que;
void ComputeAdvice(int *arr, int N, int K, int M)
{
int i,k;
for (i=0;i<N;i++) C[i+1] = arr[i]+1;
for (i=1;i<=N;i++) next_[i] = 1e9;
for (i=N;i;i--){
recent[i] = next_[C[i]];
next_[C[i]] = i;
}
for (i=1;i<=K;i++) in_scaffold[i] = 1, que.push(pii(next_[i],i));
for (i=1;i<=K;i++) first_active[i] = 0;
for (i=1;i<=N;i++) request_active[i] = 0;
for (i=1;i<=N;i++){
if (in_scaffold[C[i]]){
if (request_num[C[i]]) request_active[request_num[C[i]]] = 1;
else first_active[C[i]] = 1;
request_num[C[i]] = i;
que.push(pii(recent[i],C[i]));
continue;
}
k = que.top().second; que.pop();
in_scaffold[C[i]] = 1; in_scaffold[k] = 0;
request_num[C[i]] = i;
que.push(pii(recent[i],C[i]));
}
for (i=1;i<=K;i++) WriteAdvice(first_active[i]);
for (i=1;i<=N;i++) WriteAdvice(request_active[i]);
}
#include "assistant.h"
#include <queue>
using namespace std;
#define MAXN 100005
static int in_scaffold[MAXN],first_active[MAXN],request_active[MAXN];
static bool in_que[MAXN];
static queue<int> que;
void Assist(unsigned char *A, int N, int K, int R)
{
int i,j,k,p=0;
for (i=1;i<=K;i++) in_scaffold[i] = 1;
for (i=1;i<=K;i++){
first_active[i] = A[p++];
if (!first_active[i]) in_que[i] = 1, que.push(i);
}
for (i=1;i<=N;i++) request_active[i] = A[p++];
for (i=1;i<=N;i++){
int req=GetRequest()+1;
if (request_active[i]) in_que[req] = 0;
if (!request_active[i] && !in_que[req]) in_que[req] = 1, que.push(req);
if (in_scaffold[req]) continue;
for (;;){
k = que.front(); que.pop();
if (in_que[k]) break;
}
in_que[k] = 0;
in_scaffold[req] = 1;
in_scaffold[k] = 0;
PutBack(--k);
}
}
Compilation message (stderr)
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:13:11: warning: unused variable 'j' [-Wunused-variable]
int i,j,k,p=0;
^
# | 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... |