#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].size(), i});
vector<int> oo;
for(int i = 0; i<n; ++i){
auto it = S.find({color[C[i]].end() - lower_bound(ALL(color[C[i]]), i), C[i]});
if (it != S.end()){
pair<int, int> y = *it;
S.erase(it);
S.insert({color[C[i]].end() - upper_bound(ALL(color[C[i]]), i), y.second});
}
else{
pair<int, int> y = *S.begin();
S.erase(y);
oo.push_back(y.second);
S.insert({color[C[i]].end() - upper_bound(ALL(color[C[i]]), i), y.second});
}
}
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){
const int LOG_N = logOf(k * 2);
vector<int> oo;
for(int i = 0; i < r; i += LOG_N){
int cur = 0;
for(int j = 0; j < LOG_N; ++j) if (A[i+j]){
cur += MASK(j);
}
oo.push_back(cur);
}
vector<int> scaffold(k);
set<int> S;
for(int i= 0; i<k; ++i) {
scaffold[i] = i;
S.insert(i);
}
reverse(ALL(oo));
for(int i = 0; i<n; ++i){
int j = GetRequest();
if (S.find(j) == S.end()){
int k = oo.back(); oo.pop_back();
S.erase(scaffold[k]);
PutBack(scaffold[k]);
scaffold[k] = j;
S.insert(scaffold[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 |
1 ms |
784 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1300 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
2116 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
216 ms |
13460 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1060 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
265 ms |
16836 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
263 ms |
16552 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
250 ms |
16588 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
257 ms |
16688 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
252 ms |
16644 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
250 ms |
16792 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
251 ms |
16620 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
251 ms |
16844 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
255 ms |
16840 KB |
Output isn't correct - not an optimal way |
10 |
Correct |
232 ms |
16544 KB |
Output is partially correct - 1125615 bits used |