#include <bits/stdc++.h>
#define MAXN 100007
#include "advisor.h"
using namespace std;
static set<pair<pair<int,int>, int> > s;
static set<int> sk;
static int nxt[MAXN],lst[MAXN],cnt[MAXN],br=0,d[MAXN];
void ComputeAdvice(int *C, int N, int K, int M)
{
fill(lst,lst+N,N);
for(int i=N-1;i>=0;i--) {nxt[i]=lst[C[i]]; lst[C[i]]=i;}
for(int i=0;i<K;i++) {s.insert({{lst[i],i},br++}); sk.insert(i);}
for(int i=0;i<N;i++)
{
int a=C[i];
if(sk.find(a)!=sk.end())
{
cnt[a]++;
pair<pair<int,int>,int> p=*s.lower_bound({{i,a},0});
s.erase(p);
p.first.first=nxt[i];
s.insert(p);
}
else
{
set<pair<pair<int,int>,int> >::iterator it=s.end();
it--;
pair<pair<int,int>,int> p=*it;
s.erase(p); sk.erase(p.first.second);
d[p.second]=cnt[p.first.second]; cnt[p.first.second]=0;
p={{nxt[i],a},br++};
s.insert(p); sk.insert(a);
}
}
for(set<pair<pair<int,int>,int> >::iterator it=s.begin();it!=s.end();it++)
{
pair<pair<int,int>,int> p=*it;
d[p.second]=cnt[p.first.second];
}
for(int i=0;i<br;i++)
{
for(int j=0;j<d[i];j++) WriteAdvice(1);
WriteAdvice(0);
}
}
#include <bits/stdc++.h>
#define MAXN 100007
#include "assistant.h"
using namespace std;
static vector<int> d;
static queue<int> q;
static int cnt[MAXN];
void Assist(unsigned char *A, int N, int K, int R)
{
int t=0,p=0;
for(int i=0;i<N;i++)
{
if(A[i]==1) t++;
else {d.push_back(t); t=0;}
}
for(int i=0;i<K;i++) {cnt[i]=d[p++]; if(cnt[i]==0) q.push(i);}
for(int i=0;i<N;i++)
{
int r=GetRequest();
if(cnt[r]!=0) {cnt[r]--; if(cnt[r]==0) q.push(r);}
else
{
cnt[r]=d[p++];
PutBack(q.front());
q.pop();
if(cnt[r]==0) q.push(r);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1016 KB |
Output is correct |
2 |
Incorrect |
10 ms |
1032 KB |
Error - Putting back a color when it is already on the scaffold |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
1792 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
138 ms |
10480 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1300 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
12120 KB |
Error - Putting back a color when it is already on the scaffold |
2 |
Incorrect |
167 ms |
12224 KB |
Error - Putting back a color when it is already on the scaffold |
3 |
Incorrect |
165 ms |
13040 KB |
Error - Putting back a color when it is already on the scaffold |
4 |
Incorrect |
169 ms |
13040 KB |
Error - Putting back a color when it is already on the scaffold |
5 |
Incorrect |
162 ms |
13040 KB |
Error - Putting back a color when it is already on the scaffold |
6 |
Incorrect |
169 ms |
13040 KB |
Error - Putting back a color when it is already on the scaffold |
7 |
Incorrect |
176 ms |
13040 KB |
Error - Putting back a color when it is already on the scaffold |
8 |
Incorrect |
162 ms |
13040 KB |
Error - Putting back a color when it is already on the scaffold |
9 |
Incorrect |
177 ms |
13168 KB |
Error - Putting back a color when it is already on the scaffold |
10 |
Correct |
151 ms |
13048 KB |
Output is correct - 125000 bits used |