#include <bits/stdc++.h>
#include "advisor.h"
#define pb push_back
using namespace std;
const int MM = 2e6 + 5;
bool onn[MM];
vector <int> st[MM];
void ComputeAdvice(int *C, int N, int K, int M) {
for (int i=N-1;i>=0;i--){
st[C[i]].pb(i);
}
set <pair<int,int> > stt;
for (int i=0;i<K;i++){
onn[i] = 1;
int val = 0;
if (!st[i].size()) val=1e9;
else val=st[i].back();
stt.insert({val,i});
}
int i;
vector <int> vec;
for (i = 0; i < N; i++) {
int req = C[i];
if (onn[req]) {
vec.pb(-1);
int val = 0;
if (!st[req].size()) val=1e9;
else val=st[req].back();
stt.erase(stt.find({val,req}));
while (st[req].size() && st[req].back() <= i){
st[req].pop_back();
}
val = 0;
if (!st[req].size()) val=1e9;
else val=st[req].back();
stt.insert({val,req});
continue;
}
int idx=(--stt.end())->second; stt.erase(--stt.end());
vec.pb(idx);
onn[idx] = 0;
onn[req] = 1;
while (st[req].size() && st[req].back() <= i){
st[req].pop_back();
}
int val = 0;
if (!st[req].size()) val=1e9;
else val=st[req].back();
stt.insert({val,req});
}
int BL = sqrt(N);
int bt1 = max(log2(N/BL),log2(N/BL));
int bt2 = log2(N);
int total1 = 2*N * bt1;
int total2 = N * bt2;
int tp = 0,bt;
if (total2 <= total1) {
bt = bt2;
tp=2;
}
else {
bt = bt1;
tp=1;
}
for (int x: vec){
if (x==-1) continue;
if (tp == 2){
for (int j = bt; j >= 0; j--){
if (((x >> j) & 1)) WriteAdvice(1);
else WriteAdvice(0);
}
continue;
}
int blID = x / BL;
for (int j = bt; j >= 0; j--){
if (((blID >> j) & 1)) WriteAdvice(1);
else WriteAdvice(0);
}
int iID = x - blID * BL;
for (int j = bt; j >= 0; j--){
if (((iID >> j) & 1)) WriteAdvice(1);
else WriteAdvice(0);
}
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
int CC[2000005];
bool on[2000005];
void Assist(unsigned char *A, int N, int K, int R) {
int BL = sqrt(N);
int bt1 = max(log2(N/BL),log2(N/BL));
int bt2 = log2(N);
int total1 = 2*N * bt1;
int total2 = N * bt2;
int tp = 0,bt;
if (total2 <= total1) {
bt = bt2;
tp=2;
}
else {
bt = bt1;
tp=1;
}
int id=0;
for (int i = 0; i < R; i += bt + 1){
for (int j = i; j <= i + bt; j++){
if (A[j] == 1) CC[id] |= (1<<(bt-(j-i)));
}
id+=1;
}
for (int i=0;i<K;i++) on[i] = 1;
int i;
int l = 0;
for (i = 0; i < N; i++) {
int req = GetRequest();
if (on[req]) {
continue;
}
int idx;
if (tp==1){
int blID = CC[l++];
int iID = CC[l++];
idx = blID * BL + iID;
}else{
idx = CC[l++];
}
PutBack(idx);
on[idx] = 0;
on[req] = 1;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
47820 KB |
Output is correct |
2 |
Correct |
21 ms |
47708 KB |
Output is correct |
3 |
Correct |
29 ms |
47964 KB |
Output is correct |
4 |
Correct |
24 ms |
48036 KB |
Output is correct |
5 |
Correct |
29 ms |
48416 KB |
Output is correct |
6 |
Correct |
36 ms |
48264 KB |
Output is correct |
7 |
Correct |
26 ms |
48160 KB |
Output is correct |
8 |
Correct |
28 ms |
48372 KB |
Output is correct |
9 |
Correct |
26 ms |
48364 KB |
Output is correct |
10 |
Correct |
24 ms |
48336 KB |
Output is correct |
11 |
Correct |
24 ms |
48320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
48988 KB |
Output is correct |
2 |
Correct |
79 ms |
52380 KB |
Output is correct |
3 |
Correct |
234 ms |
61564 KB |
Output is correct |
4 |
Correct |
237 ms |
63272 KB |
Output is correct |
5 |
Correct |
227 ms |
62748 KB |
Output is correct |
6 |
Correct |
220 ms |
60860 KB |
Output is correct |
7 |
Correct |
167 ms |
59444 KB |
Output is correct |
8 |
Correct |
168 ms |
60832 KB |
Output is correct |
9 |
Correct |
230 ms |
61836 KB |
Output is correct |
10 |
Correct |
164 ms |
59204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
56972 KB |
Output is correct |
2 |
Correct |
162 ms |
59296 KB |
Output is correct |
3 |
Correct |
201 ms |
59256 KB |
Output is correct |
4 |
Correct |
175 ms |
58672 KB |
Output is correct |
5 |
Correct |
161 ms |
56752 KB |
Output is correct |
6 |
Correct |
199 ms |
59220 KB |
Output is correct |
7 |
Correct |
225 ms |
58932 KB |
Output is correct |
8 |
Correct |
212 ms |
63352 KB |
Output is correct |
9 |
Correct |
163 ms |
55652 KB |
Output is correct |
10 |
Correct |
238 ms |
59524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
47992 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
59592 KB |
Output is partially correct - 875347 bits used |
2 |
Correct |
239 ms |
59320 KB |
Output is partially correct - 841041 bits used |
3 |
Correct |
186 ms |
59272 KB |
Output is partially correct - 807466 bits used |
4 |
Correct |
225 ms |
59360 KB |
Output is partially correct - 806939 bits used |
5 |
Correct |
204 ms |
59264 KB |
Output is partially correct - 805358 bits used |
6 |
Correct |
194 ms |
59332 KB |
Output is partially correct - 807109 bits used |
7 |
Correct |
194 ms |
59264 KB |
Output is partially correct - 805902 bits used |
8 |
Correct |
195 ms |
59608 KB |
Output is partially correct - 808452 bits used |
9 |
Correct |
179 ms |
59268 KB |
Output is partially correct - 807874 bits used |
10 |
Correct |
223 ms |
63280 KB |
Output is partially correct - 1266636 bits used |