#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+1});
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(0);
}
else{
pair<int, int> y = *S.rbegin();
S.erase(y);
oo.push_back(y.second);
S.insert({*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);
for(int i= 0; i<k; ++i) scaffold[i] = i;
for(int i: oo){
int j = GetRequest();
if (i > 0) {
PutBack(scaffold[i-1]);
scaffold[i-1] = j;
}
}
}
// 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 |
784 KB |
Output is correct |
2 |
Correct |
1 ms |
780 KB |
Output is correct |
3 |
Correct |
4 ms |
1044 KB |
Output is correct |
4 |
Correct |
3 ms |
1096 KB |
Output is correct |
5 |
Correct |
3 ms |
1100 KB |
Output is correct |
6 |
Correct |
10 ms |
1672 KB |
Output is correct |
7 |
Correct |
9 ms |
1440 KB |
Output is correct |
8 |
Correct |
10 ms |
1440 KB |
Output is correct |
9 |
Correct |
10 ms |
1440 KB |
Output is correct |
10 |
Correct |
15 ms |
1472 KB |
Output is correct |
11 |
Correct |
11 ms |
1452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2408 KB |
Output is correct |
2 |
Correct |
117 ms |
8200 KB |
Output is correct |
3 |
Correct |
279 ms |
19172 KB |
Output is correct |
4 |
Correct |
128 ms |
12460 KB |
Output is correct |
5 |
Correct |
231 ms |
14060 KB |
Output is correct |
6 |
Correct |
239 ms |
15788 KB |
Output is correct |
7 |
Correct |
283 ms |
17428 KB |
Output is correct |
8 |
Correct |
227 ms |
15460 KB |
Output is correct |
9 |
Correct |
101 ms |
11892 KB |
Output is correct |
10 |
Correct |
334 ms |
18268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
14628 KB |
Output is correct |
2 |
Correct |
271 ms |
17980 KB |
Output is correct |
3 |
Correct |
259 ms |
17996 KB |
Output is correct |
4 |
Correct |
273 ms |
18064 KB |
Output is correct |
5 |
Correct |
253 ms |
17632 KB |
Output is correct |
6 |
Correct |
300 ms |
17920 KB |
Output is correct |
7 |
Correct |
268 ms |
18000 KB |
Output is correct |
8 |
Correct |
291 ms |
17780 KB |
Output is correct |
9 |
Correct |
260 ms |
18224 KB |
Output is correct |
10 |
Correct |
313 ms |
17952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1068 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
17656 KB |
Output is partially correct - 1500000 bits used |
2 |
Correct |
272 ms |
17704 KB |
Output is partially correct - 1500000 bits used |
3 |
Correct |
268 ms |
17872 KB |
Output is partially correct - 1500000 bits used |
4 |
Correct |
278 ms |
17896 KB |
Output is partially correct - 1500000 bits used |
5 |
Correct |
280 ms |
17904 KB |
Output is partially correct - 1500000 bits used |
6 |
Correct |
262 ms |
17800 KB |
Output is partially correct - 1500000 bits used |
7 |
Correct |
296 ms |
17764 KB |
Output is partially correct - 1497585 bits used |
8 |
Correct |
265 ms |
17840 KB |
Output is partially correct - 1500000 bits used |
9 |
Correct |
295 ms |
17648 KB |
Output is partially correct - 1500000 bits used |
10 |
Correct |
299 ms |
17928 KB |
Output is partially correct - 1500000 bits used |