This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5 + 10;
//#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug(...)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
#warning static (advisor)
static int subtask;
static set<pii> st; //pii(when we neet i, i) -- you remove GREATEST of them.
static bool has[MAXN];
static vector<int> inds[MAXN];
void ComputeAdvice (int *C, int N, int K, int M) {
debug("--------------------------------BEGIN ADVISOR-----------------------------------\n");
//let's just implement -- get the bits
for (int i = 0; i < N; i++) {
inds[i].push_back(N);
}
for (int i = N - 1; i >= 0; i--) {
inds[C[i]].push_back(i);
}
for (int i = 0; i < K; i++) {
has[i] = true;
st.emplace(inds[i].back(), i);
}
vector<int> ans;
for (int i = 0; i < N; i++) {
inds[C[i]].pop_back();
if (has[C[i]]) {
st.erase(pii(inds[C[i]].back(), C[i]));
st.insert(pii(inds[C[i]].back(), C[i]));
debug("No action\n");
ans.push_back(N); //this is bad
continue;
}
//remove one
auto it = --st.end();
pii tp = *it;
st.erase(it);
has[tp.se] = false;
debug("Put %d away, put %d in.\n", tp.se, C[i]);
ans.push_back(tp.se);
st.insert(pii(inds[C[i]].back(), C[i]));
//add C[i]
has[C[i]] = true;
}
//the end of computing.
int logn = 31 - __builtin_clz(N);
for (int x : ans) {
debug("-----x = %d-------\n", x);
for (int i = logn; i >= 0; i--) {
WriteAdvice((x >> i) & 1);
debug("AA %d\n", (x >> i) & 1);
}
}
debug("--------------------------------DONE WITH THE ADVISOR-----------------------------------\n");
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug(...)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
#warning static (assistant)
static int subtask;
void Assist (unsigned char *A, int N, int K, int R) {
debug("--------------------------------BEGIN ASSISTANT-----------------------------------\n");
int logn = 31 - __builtin_clz(N);
for (int i = 0; i < N; i++) {
GetRequest();
int x = 0;
for (int j = 0; j <= logn; j++) {
int pos = (logn + 1) * i + j;
debug("Advice = %d\n", A[pos]);
x = 2 * x + A[pos];
}
if (x != N) {
debug("put %d away\n", x);
PutBack(x);
}
}
debug("--------------------------------DONE WITH THE ASSISTANT-----------------------------------\n");
}
Compilation message (stderr)
advisor.cpp:17:2: warning: #warning static (advisor) [-Wcpp]
#warning static (advisor)
^~~~~~~
advisor.cpp:19:12: warning: 'subtask' defined but not used [-Wunused-variable]
static int subtask;
^~~~~~~
assistant.cpp:16:2: warning: #warning static (assistant) [-Wcpp]
#warning static (assistant)
^~~~~~~
assistant.cpp:18:12: warning: 'subtask' defined but not used [-Wunused-variable]
static int subtask;
^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |