#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
for(auto i: a) out << i << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
void ComputeAdvice(int *C, int n, int k, int m){
vector<vector<int>> color(n);
for(int i = 0; i<n; ++i) color[C[i]].push_back(i);
for(int i = 0; i<n; ++i) color[i].push_back(n);
set<pair<int, int>> S;
for(int i = 0; i<k; ++i) S.insert({color[i][0], i});
vector<int> oo;
for(int i = 0; i<n; ++i){
auto it = S.begin();
if ((*it).first == i){
pair<int, int> y = *it;
S.erase(it);
S.insert({*upper_bound(ALL(color[C[i]]), i), y.second});
oo.push_back(-1);
}
else{
auto it = S.end();
it--;
if (it != S.begin()){
it--;
if ((*it).first < i + k) it++;
}
pair<int, int> y = *it;
S.erase(y);
oo.push_back(y.second);
S.insert({*upper_bound(ALL(color[C[i]]), i), y.second});
}
}
vector<int> nxt(k, n-1);
vector<int> info;
for(int i = n-1; i>=0; --i) if (oo[i] > -1){
int cnt = upper_bound(ALL(color[C[i]]), nxt[oo[i]]) - upper_bound(ALL(color[C[i]]), i);
info.push_back(cnt > 0);
nxt[oo[i]] = i;
}
for(int i = k-1; i>=0; --i){
int cnt = upper_bound(ALL(color[i]), nxt[i]) - lower_bound(ALL(color[i]), 0);
info.push_back(cnt > 0);
}
reverse(ALL(info));
// printArr(info);
for(int i: info) WriteAdvice(i);
// const int LOG_N = logOf(k * 2);
// for(int i: oo){
// for(int j = 0; j < LOG_N; ++j){
// WriteAdvice(i % 2);
// i /= 2;
// }
// }
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int C[] = {2, 0, 3, 0};
// ComputeAdvice(C, 4, 2, 1000);
// return 0;
// }
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
for(auto i: a) out << i << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
void Assist(unsigned char *A, int n, int k, int r){
vector<int> state(k);
for(int i = 0; i<k; ++i) state[i] = A[i];
set<int> replacable;
for(int i = 0; i<k; ++i) if (state[i] == 0) replacable.insert(i);
vector<int> info;
for(int i = k; i<r; ++i) info.push_back(A[i]);
reverse(ALL(info));
vector<int> scaffold(k);
set<int> S;
for(int i= 0; i<k; ++i) {
scaffold[i] = i;
S.insert(i);
}
for(int i = 0; i<n; ++i){
int j = GetRequest();
if (S.find(j) == S.end()){
if (replacable.empty()){
int k = 0;
PutBack(scaffold[k]);
S.erase(scaffold[k]);
scaffold[k] = j;
S.insert(scaffold[k]);
state[k] = info.back(); info.pop_back();
if (state[k] == 0) replacable.insert(k);
}
else{
int k = *replacable.begin();
replacable.erase(k);
PutBack(scaffold[k]);
S.erase(scaffold[k]);
scaffold[k] = j;
S.insert(scaffold[k]);
state[k] = info.back(); info.pop_back();
if (state[k] == 0) replacable.insert(k);
}
}
else{
}
}
}
// void PutBack(int T);
// int GetRequest();
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
780 KB |
Output is correct |
2 |
Incorrect |
0 ms |
780 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1888 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
82 ms |
11772 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1064 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
106 ms |
14084 KB |
Execution killed with signal 11 |
2 |
Runtime error |
94 ms |
14216 KB |
Execution killed with signal 11 |
3 |
Runtime error |
110 ms |
15288 KB |
Execution killed with signal 11 |
4 |
Runtime error |
97 ms |
14996 KB |
Execution killed with signal 11 |
5 |
Runtime error |
107 ms |
15048 KB |
Execution killed with signal 11 |
6 |
Runtime error |
120 ms |
15016 KB |
Execution killed with signal 11 |
7 |
Runtime error |
101 ms |
15008 KB |
Execution killed with signal 11 |
8 |
Runtime error |
104 ms |
14920 KB |
Execution killed with signal 11 |
9 |
Runtime error |
98 ms |
14860 KB |
Execution killed with signal 11 |
10 |
Correct |
98 ms |
11924 KB |
Output is correct - 99509 bits used |