#include "advisor.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
using namespace std;
void ComputeAdvice(int *C, int n, int k, int m) {
int L = 13;
auto W = [&](int x) -> void {
for(int i = L-1; i >= 0; i--) WriteAdvice(x >> i & 1);
};
for(int i = 0; i < n; i++) W(C[i]);
/*
vector<bool> ok(n);
for(int i = 0; i < k; i++) ok[i] = true;
vector<int> nxt(n), last(n, n);
for(int i = n-1; i >= 0; i--) {
nxt[i] = last[C[i]];
last[C[i]] = i;
}
priority_queue<pair<int,int>> pq;
for(int i = 0; i < k; i++) pq.push({last[i], i});
for(int i = 0; i < n; i++) {
int r = C[i];
if(!ok[r]) {
int x = pq.top().second; pq.pop();
W(x);
ok[x] = false;
ok[r] = true;
pq.push({nxt[i], r});
}
}
*/
}
#include "assistant.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
using namespace std;
void Assist(unsigned char *A, int n, int k, int len) {
int L = 13;
int p = 0;
auto nextint = [&]() -> int {
int res = 0;
for(int i = 0; i < L; i++) {
res = res * 2 + int(A[p++]);
}
assert(p <= len);
return res;
};
vector<int> C(n);
for(int i = 0; i < n; i++) C[i] = nextint();
vector<bool> ok(n);
for(int i = 0; i < k; i++) ok[i] = true;
vector<int> nxt(n), last(n, n);
for(int i = n-1; i >= 0; i--) {
nxt[i] = last[C[i]];
last[C[i]] = i;
}
priority_queue<pair<int,int>> pq;
for(int i = 0; i < k; i++) pq.push({last[i], i});
for(int i = 0; i < n; i++) {
int r = GetRequest();
assert(r == C[i]);
if(!ok[r]) {
int x = pq.top().second; pq.pop();
PutBack(x);
ok[x] = false;
ok[r] = true;
pq.push({nxt[i], r});
}
}
/*
vector<bool> ok(n);
for(int i = 0; i < k; i++) ok[i] = true;
for(int i = 0; i < n; i++) {
int r = GetRequest();
if(!ok[r]) {
int x = nextint();
PutBack(x);
ok[x] = false;
ok[r] = true;
}
}
*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
772 KB |
Output is correct |
2 |
Incorrect |
2 ms |
784 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
33 ms |
2532 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
255 ms |
12844 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1008 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
333 ms |
15664 KB |
Execution killed with signal 11 |
2 |
Runtime error |
352 ms |
15548 KB |
Execution killed with signal 11 |
3 |
Runtime error |
327 ms |
15800 KB |
Execution killed with signal 11 |
4 |
Runtime error |
322 ms |
15888 KB |
Execution killed with signal 11 |
5 |
Runtime error |
316 ms |
15980 KB |
Execution killed with signal 11 |
6 |
Runtime error |
324 ms |
15916 KB |
Execution killed with signal 11 |
7 |
Runtime error |
329 ms |
15848 KB |
Execution killed with signal 11 |
8 |
Runtime error |
321 ms |
15604 KB |
Execution killed with signal 11 |
9 |
Runtime error |
320 ms |
15740 KB |
Execution killed with signal 11 |
10 |
Runtime error |
328 ms |
15848 KB |
Execution killed with signal 11 |