#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) {
int BL = sqrt(N);
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 bt = log2(N/BL);
for (int x: vec){
if (x==-1) 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 bt = log2(N/BL);
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 blID = CC[l++];
int iID = CC[l++];
int idx = blID * BL + iID;
PutBack(idx);
on[idx] = 0;
on[req] = 1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
49756 KB |
Output is correct |
2 |
Correct |
16 ms |
49740 KB |
Output is correct |
3 |
Correct |
22 ms |
50016 KB |
Output is correct |
4 |
Correct |
20 ms |
49992 KB |
Output is correct |
5 |
Incorrect |
18 ms |
48100 KB |
Error - advice is too long |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
50732 KB |
Output is correct |
2 |
Correct |
75 ms |
53520 KB |
Output is correct |
3 |
Correct |
213 ms |
64516 KB |
Output is correct |
4 |
Correct |
245 ms |
66472 KB |
Output is correct |
5 |
Correct |
250 ms |
65840 KB |
Output is correct |
6 |
Correct |
196 ms |
64064 KB |
Output is correct |
7 |
Correct |
177 ms |
62632 KB |
Output is correct |
8 |
Correct |
181 ms |
64140 KB |
Output is correct |
9 |
Correct |
226 ms |
64752 KB |
Output is correct |
10 |
Correct |
159 ms |
62272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
60228 KB |
Output is correct |
2 |
Correct |
167 ms |
62364 KB |
Output is correct |
3 |
Correct |
158 ms |
62168 KB |
Output is correct |
4 |
Correct |
149 ms |
61664 KB |
Output is correct |
5 |
Correct |
132 ms |
57680 KB |
Output is correct |
6 |
Correct |
161 ms |
62372 KB |
Output is correct |
7 |
Correct |
157 ms |
61988 KB |
Output is correct |
8 |
Correct |
206 ms |
66560 KB |
Output is correct |
9 |
Correct |
104 ms |
56796 KB |
Output is correct |
10 |
Correct |
176 ms |
62168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
47960 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
62544 KB |
Output is partially correct - 926838 bits used |
2 |
Correct |
175 ms |
62476 KB |
Output is partially correct - 890514 bits used |
3 |
Correct |
159 ms |
62124 KB |
Output is partially correct - 854964 bits used |
4 |
Correct |
158 ms |
62180 KB |
Output is partially correct - 854406 bits used |
5 |
Correct |
160 ms |
62368 KB |
Output is partially correct - 852732 bits used |
6 |
Correct |
162 ms |
62356 KB |
Output is partially correct - 854586 bits used |
7 |
Correct |
162 ms |
62168 KB |
Output is partially correct - 853308 bits used |
8 |
Correct |
160 ms |
62116 KB |
Output is partially correct - 856008 bits used |
9 |
Correct |
158 ms |
62228 KB |
Output is partially correct - 855396 bits used |
10 |
Correct |
202 ms |
66168 KB |
Output is partially correct - 1341144 bits used |