#include "advisor.h"
#include<queue>
using namespace std;
typedef pair<int,int> ppair;
priority_queue<ppair>q;
int a[100010],ch[100010],arr[100010],w,paint2[100010],dap[100010],pdap[25010];
void ComputeAdvice(int *C, int N, int K, int M)
{
int i,p,p2;
for(i=N-1;i>=0;i--)
{
if(ch[C[i]]==0) a[i]=N;
else a[i]=ch[C[i]];
ch[C[i]]=i;
}
for(i=0;i<K;i++)
{
paint2[i]=1;
if(ch[i]==0) q.push(make_pair(N,-i-1));
else q.push(make_pair(ch[i],-i-1));
arr[i]=-1;
}
for(i=0;i<=N-1;i++)
{
if(paint2[C[i]]==1)
{
arr[C[i]]=i; continue;
}
p=q.top().first; p2=q.top().second;
if(p2<=-1) pdap[-p2-1]=1;
else dap[arr[C[p2]]]=1;
if(p2<=-1) paint2[-p2-1]--;
else paint2[C[p2]]--;
q.pop();
if(a[C[i]]==0) q.push(make_pair(N,i));
else q.push(make_pair(a[i],i));
paint2[C[i]]++;
arr[C[i]]=i;
}
for(i=0;i<K;i++)
{
if(arr[i]==-1) pdap[i]=1;
}
for(i=0;i<K;i++)
{
WriteAdvice(pdap[i]);
}
for(i=0;i<N;i++)
{
WriteAdvice(dap[i]);
}
}
#include "assistant.h"
int paint[100010],request[100010],st[100010],top,ch2[100010],c;
void Assist(unsigned char *A, int N, int K, int R)
{
int i;
for(i=0;i<K;i++) paint[i]=A[i];
for(i=0;i<N;i++) request[i]=A[K+i];
for(i=0;i<K;i++)
{
if(paint[i]==1) st[++top]=i;
ch2[i]++;
}
for(i=0;i<N;i++)
{
c=GetRequest();
if(ch2[c]==1)
{
if(request[i]==1) st[++top]=c;
continue;
}
PutBack(st[top]);
ch2[c]++;
ch2[st[top]]--;
st[top--]=0;
if(request[i]==1) st[++top]=c;
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:9:11: warning: variable 'p' set but not used [-Wunused-but-set-variable]
int i,p,p2;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
616 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1112 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1960 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
7288 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
7288 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
8480 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
80 ms |
8568 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
97 ms |
8568 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
81 ms |
8648 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
83 ms |
8648 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
91 ms |
8648 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
99 ms |
8856 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
78 ms |
8856 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
77 ms |
8856 KB |
Output isn't correct - not an optimal way |
10 |
Correct |
98 ms |
8888 KB |
Output is correct - 125000 bits used |