#include "advisor.h"
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
void ComputeAdvice(int *c, int n, int k, int m)
{
vector <ll> cnt(n+k, 0), a(k), p(n);
iota(a.begin(), a.end(), n);
for (ll i=0; i<n; i++) p[i]=i<k?i:-1;
vector <vector <ll>> pos(n);
for (ll i=n-1; i>=0; i--) pos[c[i]].pb(i);
auto get=[&](ll i) {return pos[i].size()?pos[i].back():n+1;};
set <pll> s;
for (ll i=0; i<k; i++)
s.insert({get(i), i});
for (ll i=0; i<n; i++)
{
if (p[c[i]]!=-1)
{
cnt[a[p[c[i]]]]++;
s.erase(s.find({get(c[i]), c[i]}));
pos[c[i]].pop_back();
s.insert({get(c[i]), c[i]});
}
else
{
ll id=(*prev(s.end())).se;
s.erase(prev(s.end()));
pos[c[i]].pop_back();
a[p[id]]=i, p[c[i]]=p[id], p[id]=-1;
s.insert({get(c[i]), c[i]});
}
}
for (ll i=n; i<n+k; i++)
{
for (ll j=0; j<cnt[i]; j++) WriteAdvice(1);
WriteAdvice(0);
}
for (ll i=0; i<n; i++)
{
for (ll j=0; j<cnt[i]; j++) WriteAdvice(1);
WriteAdvice(0);
}
return;
}
#include "assistant.h"
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
void Assist(unsigned char *a, int n, int k, int r)
{
ll ptr=0;
vector <ll> ok, cnt(k, 0), p(n, -1);
auto get=[&]()
{
ll ans=0;
while (a[ptr]==1) ans++, ptr++;
ptr++; return ans;
};
for (ll i=0; i<k; i++)
{
cnt[i]=get(), p[i]=i;
if (!cnt[i]) ok.pb(i);
}
for (ll i=0; i<n; i++)
{
ll cr=GetRequest();
cout << cr << endl;
if (p[cr]!=-1)
{
cnt[cr]--;
if (!cnt[cr]) ok.pb(cr);
}
else
{
ll id=ok.back(); ok.pop_back();
PutBack(id), p[cr]=id, cnt[id]=get();
if (!cnt[id]) ok.pb(id);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
792 KB |
Hacked |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1900 KB |
Hacked |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
10052 KB |
Hacked |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1080 KB |
Hacked |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
11756 KB |
Hacked |
2 |
Incorrect |
88 ms |
11912 KB |
Hacked |
3 |
Incorrect |
84 ms |
12604 KB |
Hacked |
4 |
Incorrect |
131 ms |
11908 KB |
Hacked |
5 |
Incorrect |
98 ms |
11832 KB |
Hacked |
6 |
Incorrect |
92 ms |
12296 KB |
Hacked |
7 |
Incorrect |
83 ms |
11944 KB |
Hacked |
8 |
Incorrect |
81 ms |
11824 KB |
Hacked |
9 |
Incorrect |
80 ms |
11988 KB |
Hacked |
10 |
Incorrect |
78 ms |
13632 KB |
Hacked |