//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
void ComputeAdvice(int *C, int N, int K, int M); void WriteAdvice(unsigned char a);
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, m, k;
cin >> n >> k >> m;
int *c = new int[n];
for(int i = 0; i < n; ++i) cin >> c[i];
ComputeAdvice(c, n, k, m);
return 0;
}
void WriteAdvice(unsigned char a){
putchar(a + '0');
putchar(' ');
}
#else
#include "advisor.h"
#endif
const int maxn = 1e5 + 225;
queue<int> app[maxn];
void ComputeAdvice(int *C, int N, int K, int M){
int L = __lg(N - 1);
for(int i = 0; i < N; ++i) app[C[i]].emplace(i);
for(int i = 0; i < N; ++i) app[i].emplace(8e7);
vector<int> s(N);
priority_queue<pii> pq;
for(int i = 0; i < K; ++i) s[i] = 1;
for(int i = 0; i < K; ++i) pq.emplace(app[i].front(), i);
auto wn = [&L](int a){
for(int i = L; i >= 0; --i){
WriteAdvice((a >> i & 1));
}
};
for(int i = 0; i < N; ++i){
int c = C[i]; app[c].pop();
if(s[c] != 0){
wn(c);
pq.emplace(app[c].front(), c);
continue;
}
int eek;
pii tp;
do{
tp = pq.top(); pq.pop();
eek = tp.ss;
} while(s[eek] == 0);
wn(eek);
s[eek] = 0;
s[c] = 1;
pq.emplace(app[c].front(), c);
}
}
//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
void Assist(unsigned char *A, int N, int K, int R); void PutBack(int T);
int GetRequest();
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, k, r; cin >> n >> k >> r;
unsigned char * a = new unsigned char[r];
for(int i = 0; i < r; ++i) cin >> a[i];
Assist(a, n, k, r);
return 0;
}
int GetRequest(){
const int a[4] = {2, 0, 3, 0};
static int p = 0;
return a[p++];
}
void PutBack(int T){
cout << T << ' ';
}
#else
#include "assistant.h"
#endif
const int maxn = 1e5 + 225;
void Assist(unsigned char *A, int N, int K, int R){
int L = __lg(N - 1);
auto GC = [&](){
static int p = 0;
return (int)A[p++];
};
for(int i = 0; i < N; ++i){
int c = GetRequest();
int ans = 0;
for(int i = 0; i <= L; ++i){
ans = (ans << 1) | (GC());
}
//debug(ans);
if(ans == c) continue;
PutBack(ans);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
68324 KB |
Output is correct |
2 |
Correct |
53 ms |
68324 KB |
Output is correct |
3 |
Correct |
56 ms |
68348 KB |
Output is correct |
4 |
Correct |
61 ms |
68580 KB |
Output is correct |
5 |
Correct |
69 ms |
68732 KB |
Output is correct |
6 |
Correct |
68 ms |
68820 KB |
Output is correct |
7 |
Correct |
68 ms |
68864 KB |
Output is correct |
8 |
Correct |
69 ms |
68732 KB |
Output is correct |
9 |
Correct |
67 ms |
68732 KB |
Output is correct |
10 |
Correct |
69 ms |
68860 KB |
Output is correct |
11 |
Correct |
69 ms |
68784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
69420 KB |
Output is correct |
2 |
Correct |
259 ms |
74532 KB |
Output is correct |
3 |
Correct |
500 ms |
80576 KB |
Output is correct |
4 |
Correct |
493 ms |
80860 KB |
Output is correct |
5 |
Correct |
489 ms |
80760 KB |
Output is correct |
6 |
Correct |
497 ms |
80816 KB |
Output is correct |
7 |
Correct |
495 ms |
80908 KB |
Output is correct |
8 |
Correct |
429 ms |
79272 KB |
Output is correct |
9 |
Correct |
463 ms |
80200 KB |
Output is correct |
10 |
Correct |
495 ms |
80780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
78408 KB |
Output is correct |
2 |
Incorrect |
111 ms |
71524 KB |
Error - advice is too long |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
68196 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
497 ms |
81268 KB |
Output is partially correct - 1700000 bits used |
2 |
Correct |
500 ms |
80940 KB |
Output is partially correct - 1700000 bits used |
3 |
Correct |
496 ms |
80952 KB |
Output is partially correct - 1700000 bits used |
4 |
Correct |
514 ms |
80668 KB |
Output is partially correct - 1700000 bits used |
5 |
Correct |
493 ms |
80696 KB |
Output is partially correct - 1700000 bits used |
6 |
Correct |
494 ms |
80816 KB |
Output is partially correct - 1700000 bits used |
7 |
Correct |
497 ms |
80784 KB |
Output is partially correct - 1697263 bits used |
8 |
Correct |
497 ms |
80732 KB |
Output is partially correct - 1700000 bits used |
9 |
Correct |
495 ms |
80644 KB |
Output is partially correct - 1700000 bits used |
10 |
Correct |
507 ms |
80632 KB |
Output is partially correct - 1700000 bits used |