#include<bits/stdc++.h>
#include "advisor.h"
using namespace std;
const int maxn = 1e5 + 10;
int last[maxn], bitcnt;
int getlog(int x)
{
for (int i = 0; i < 20; ++ i)
{
int p = (1 << i);
if(p > x)return i-1;
}
}
void givebits(int x)
{
for (int i = 0; i < bitcnt; ++ i)
{
if((1 << i) & x)WriteAdvice(1);
else WriteAdvice(0);
}
}
map < int, int > mp;
deque < int > as[maxn];
void ComputeAdvice(int *C, int N, int K, int M)
{
mp.clear();
int n = N;
int k = K;
int m = M;
bitcnt = getlog(N) + 1;
// cout << "bitcount " << bitcnt << endl;
for (int i = 0; i < n; ++ i)
{
as[C[i]].push_back(i);
}
for (int i = 0; i < n; ++ i)
{
as[i].push_back(n);
}
set < pair < int, int > > q;
for (int i = 0; i < K; ++ i)
{
mp[i] = 1;
q.insert(make_pair(as[i].front(), i));
}
for (int i = 0; i < n; ++ i)
{
assert(q.size() == K);
if(mp[C[i]])
{
WriteAdvice(0);
//givebits(n);
as[C[i]].pop_front();
int newlast = as[C[i]].front();
q.erase(make_pair(i, C[i]));
q.insert(make_pair(newlast, C[i]));
}
else
{
WriteAdvice(1);
pair < int, int > w = *q.rbegin();
assert(mp[w.second]);
int index = w.second;
// cout << " remove " << index << endl;
q.erase(w);
//cout << "- " << w.first << " " << w.second << endl;
// assert(index != 310);
givebits((index));
as[C[i]].pop_front();
int newlast = as[C[i]].front();
q.insert(make_pair(newlast, C[i]));
// if(index == 310)cout << "PROBLEM PROBLEM " << C[i] << endl;
// cout << "+ " << newlast << " " << C[i] << endl;
mp[index] = 0;
mp[C[i]] = 1;
}
}
}
#include <bits/stdc++.h>
#include "assistant.h"
#define pb push_back
using namespace std;
const int maxnn = 1e5 + 10;
vector < int > g;
int n, bitche;
int getlog2(int x)
{
for (int i = 0; i < 20; ++ i)
{
int p = (1 << i);
if(p > x)return i-1;
}
}
int curr_bit = 0;
int get_bits()
{
int ans = 0;
for (int i = 0; i < bitche; ++ i)
{
if(g[curr_bit])ans = (ans | (1 << i));
curr_bit ++;
}
return ans;
}
void Assist(unsigned char *A, int N, int K, int R)
{
n = N;
bitche = getlog2(N) + 1;
// cout << "bitche = " << bitche << endl;
for (int i = 0; i < R; ++ i)
{
g.pb(A[i]);
}
for (int i = 0; i < N; ++ i)
{
int curr = GetRequest();
int type = g[curr_bit];
// assert(g.size())
curr_bit ++;
if(type == 0)continue;
int x = get_bits();
// if(x == 310)cout << i << endl;
//assert(x != 310);
PutBack(x);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# 1번째 컴파일 단계
advisor.cpp: In function 'int getlog(int)':
advisor.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
13 | }
| ^
# 2번째 컴파일 단계
assistant.cpp: In function 'int getlog2(int)':
assistant.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
16 | }
| ^
# | 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... |