#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void WriteAdvice(unsigned char a);
void write(int bits, int x) {
for (int i = 0; i < bits; i++) {
WriteAdvice((x >> i) & 1);
}
}
void ComputeAdvice(int *arr, int n, int k, int) {
int bits = __lg(k - 1) + 1;
vector<int> inds[n];
for (int i = 0; i < n; i++) {
inds[arr[i]].push_back(i);
}
for (auto& a : inds) {
a.push_back(n);
reverse(begin(a), end(a));
}
int in[n];
memset(in, -1, sizeof(in));
priority_queue<pair<int, int>> pq;
for (int i = 0; i < k; i++) {
pq.emplace(inds[i].back(), i);
in[i] = i;
}
for (int i = 0; i < n; i++) {
inds[arr[i]].pop_back();
if (in[arr[i]] != -1) {
continue;
}
int x = pq.top().second;
pq.pop();
write(bits, in[x]);
swap(in[x], in[arr[i]]);
pq.emplace(inds[arr[i]].back(), arr[i]);
}
}
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
int GetRequest();
void PutBack(int T);
int read(unsigned char*& ptr, int bits) {
int x = 0;
for (int i = 0; i < bits; i++) {
x |= *(ptr++) << i;
}
return x;
}
void Assist(unsigned char* buf, int n, int k, int) {
int bits = __lg(k - 1) + 1;
int vals[k], inds[n];
iota(vals, vals + k, 0);
memset(inds, -1, sizeof(inds));
iota(inds, inds + k, 0);
for (int i = 0; i < n; i++) {
int cur = GetRequest();
if (inds[cur] != -1) {
continue;
}
int x = read(buf, bits);
PutBack(vals[x]);
swap(inds[vals[x]], inds[cur]);
vals[x] = cur;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
520 KB |
Output is correct |
2 |
Incorrect |
1 ms |
512 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
1904 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
12760 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
912 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
242 ms |
16132 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
219 ms |
16116 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
221 ms |
15644 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
198 ms |
15664 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
205 ms |
15576 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
215 ms |
15624 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
197 ms |
15576 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
216 ms |
15492 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
191 ms |
15524 KB |
Output isn't correct - not an optimal way |
10 |
Correct |
252 ms |
16784 KB |
Output is partially correct - 1117620 bits used |