#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
int pointer=0;
unsigned char ad[nmax];
int seen[nmax];
int nxt_seen[nmax];
set< pair<int/*seen next*/,int/*id*/> > s;
int when_pushed[nmax];
set<int> cut_moment[nmax];
vector<int> there[nmax];
int check_next_moment(int pos,int after)
{
if(there[pos].size()==0)return 0;
int p=upper_bound(there[pos].begin(),there[pos].end(),after)-there[pos].begin();
if(p==there[pos].size())return 0;
if(cut_moment[pos].count(there[pos][p]))return 0;
return 1;
}
void ComputeAdvice(int *C,int N,int K,int M)
{
for(int i=0;i<N;i++)
seen[i]=N;
for(int i=N-1;i>=0;i--)
{
nxt_seen[i]=seen[C[i]];
seen[C[i]]=i;
}
for(int i=0;i<K;i++)
s.insert({nxt_seen[i],i});
for(int i=0;i<K;i++)
if(s.count({i,C[i]}))
{
s.erase({i,C[i]});
s.insert({nxt_seen[i],C[i]});
}
else
{
//cut the furthest
set< pair<int/*seen next*/,int/*id*/> >::iterator it=s.end();
it--;
int which=(*it).second;
cut_moment[which].insert(i);
when_pushed[C[i]]=i;
s.erase(it);
s.insert({nxt_seen[i],C[i]});
}
for(int i=0;i<N;i++)
there[C[i]].push_back(i);
for(int i=0;i<K;i++)
WriteAdvice(check_next_moment(i,-1));
for(int i=0;i<N;i++)
WriteAdvice(check_next_moment(C[i],i));
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
set<int> active,passive;
void Assist(unsigned char *A, int N, int K, int R)
{
for(int i=0;i<K;i++)
if(A[i]==1)active.insert(i);
else passive.insert(i);
for(int i=K;i<N+K;i++)
{
int cur=GetRequest();
if(active.count(cur))
{
active.erase(cur);
}
else
{
int tp=*passive.begin();
passive.erase(tp);
PutBack(tp);
}
if(A[i]==1)active.insert(cur);
else passive.insert(cur);
}
}
Compilation message
advisor.cpp: In function 'int check_next_moment(int, int)':
advisor.cpp:29:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p==there[pos].size())return 0;
~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
28928 KB |
Output is correct |
2 |
Correct |
8 ms |
28928 KB |
Output is correct |
3 |
Correct |
9 ms |
29184 KB |
Output is correct |
4 |
Incorrect |
9 ms |
29184 KB |
Error - Putting back a color that is not on the scaffold |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
30208 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
39408 KB |
Output is correct |
2 |
Correct |
159 ms |
43240 KB |
Output is correct |
3 |
Correct |
158 ms |
43760 KB |
Output is correct |
4 |
Correct |
159 ms |
42992 KB |
Output is correct |
5 |
Incorrect |
121 ms |
40688 KB |
Error - Putting back a color that is not on the scaffold |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
29440 KB |
Output is correct |
2 |
Incorrect |
13 ms |
29696 KB |
Error - Not putting back color when it is not on the scaffold |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
120 ms |
41456 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Correct |
151 ms |
41712 KB |
Output is correct - 122000 bits used |
3 |
Correct |
156 ms |
42480 KB |
Output is correct - 125000 bits used |
4 |
Incorrect |
110 ms |
42224 KB |
Error - Putting back a color when it is already on the scaffold |
5 |
Correct |
166 ms |
42224 KB |
Output is correct - 125000 bits used |
6 |
Correct |
189 ms |
42224 KB |
Output is correct - 125000 bits used |
7 |
Correct |
172 ms |
42232 KB |
Output is correct - 124828 bits used |
8 |
Correct |
155 ms |
42232 KB |
Output is correct - 124910 bits used |
9 |
Correct |
153 ms |
42224 KB |
Output is correct - 125000 bits used |
10 |
Incorrect |
100 ms |
44272 KB |
Error - Putting back a color that is not on the scaffold |