#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
int n,k,m;
bool chk[100000];
int nt[200000];
int pr[200000];
int type[200000];
typedef pair<int,int> P;
void ComputeAdvice(int *C, int N, int K, int M) {
n=N;
k=K;
m=M;
int cnt=0;
memset(pr,-1,sizeof(pr));
memset(nt,-1,sizeof(nt));
int ind=n;
set<P> s;
for(int i=0;i<k;i++) {
pr[i]=i;
}
for(int i=0;i<n;i++) {
if (pr[C[i]]!=-1) {
nt[pr[C[i]]]=i+k;
}
pr[C[i]]=i+k;
if (!chk[C[i]]) {
chk[C[i]]=true;
cnt++;
}
}
memset(pr,-1,sizeof(pr));
memset(chk,0,sizeof(chk));
for(int i=0;i<k;i++) {
s.insert(P(nt[i],i));
chk[i]=true;
}
cnt=k;
for(int i=0;i<n;i++) {
if (chk[C[i]]) {
pr[C[i]]=i+k;
continue;
}
if (cnt==k) {
P now=*s.begin();
type[now.second]=1;
chk[C[now.second]]=false;
s.erase(now);
chk[C[i]]=true;
s.insert(P(nt[i+k],i+k));
}
else {
cnt++;
chk[C[i]]=true;
s.insert(P(nt[i+k],i+k));
}
pr[C[i]]=i+k;
}
for(int i=0;i<n+k;i++) {
WriteAdvice(1-type[i]);
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
bool save[100000];
bool isin[100000];
typedef pair<int,int> P;
set<int> s;
int n,k,r;
void Assist(unsigned char *A, int N, int K, int R) {
int i;
n=N;
k=K;
r=R;
for(int i=0;i<k;i++) {
isin[i]=true;
if (A[i]==1) {
save[i]=true;
}
else {
s.insert(i);
}
}
for (i = 0; i < N; i++) {
int req = GetRequest();
if (!isin[req]) {
int now=*s.begin();
s.erase(now);
PutBack(now);
isin[now]=false;
isin[req]=true;
}
save[req]=(A[i+k]==1);
s.erase(req);
if (!save[req]) {
s.insert(req);
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:19:9: warning: unused variable 'ind' [-Wunused-variable]
19 | int ind=n;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3100 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
5460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
20 ms |
7964 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3120 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
8024 KB |
Execution killed with signal 11 |
2 |
Runtime error |
24 ms |
8532 KB |
Execution killed with signal 11 |
3 |
Runtime error |
25 ms |
8716 KB |
Execution killed with signal 11 |
4 |
Runtime error |
25 ms |
8536 KB |
Execution killed with signal 11 |
5 |
Runtime error |
25 ms |
8540 KB |
Execution killed with signal 11 |
6 |
Runtime error |
25 ms |
8528 KB |
Execution killed with signal 11 |
7 |
Runtime error |
25 ms |
8560 KB |
Execution killed with signal 11 |
8 |
Runtime error |
25 ms |
8536 KB |
Execution killed with signal 11 |
9 |
Runtime error |
24 ms |
8536 KB |
Execution killed with signal 11 |
10 |
Runtime error |
20 ms |
8632 KB |
Execution killed with signal 11 |