#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "advisor.h"
using namespace std;
using namespace __gnu_pbds;
using Set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
void ComputeAdvice(int *C, int N, int K, int M) {
set<pair<int, int>> q;
int s[N], nx[N];
bool f[N] = {false};
fill(s, s+N, N);
int c[N];
int i;
for(i = N-1;i >= 0;i--) {
nx[i] = s[C[i]];
s[C[i]] = i;
}
int sz = 0;
Set pbd;
vector<int> bad;
for(i = 0;i < K;i++){
WriteAdvice(s[i] != N);
if(s[i] != N) {
sz++;
pbd.insert(i);
q.insert({s[i], i});
} else {
bad.push_back(i);
}
f[i] = true;
c[i] = i;
}
for(i = 0;i < N-1-bad.size();i++){
if(f[C[i]]) {
int ind = q.begin()->second;
q.erase(q.begin());
WriteAdvice(nx[i] != N);
if(nx[i] == N) {
sz--;
bad.push_back(ind);
pbd.erase(pbd.find(ind));
}
else {
q.insert({nx[i], ind});
}
continue;
}
if(!bad.empty()){
int ind = bad.back();
bad.pop_back();
WriteAdvice(nx[i] != N);
if(nx[i] != N) {
sz++;
pbd.insert(ind);
q.insert({nx[i], ind});
} else bad.push_back(ind);
f[c[ind]] = false;
f[C[i]] = true;
c[ind] = C[i];
continue;
}
int ind = q.rbegin()->second;
int L = log2(sz-1) + 1;
int pind = pbd.order_of_key(ind);
for(int b = 0;b < L;b++) WriteAdvice(1&(pind>>b));
WriteAdvice(nx[i] != N);
q.erase(prev(q.end()));
if(nx[i] == N) {
sz--;
pbd.erase(pbd.find(ind));
bad.emplace_back(ind);
}
else q.insert({nx[i], ind});
f[c[ind]] = false;
f[C[i]] = true;
c[ind] = C[i];
}
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "assistant.h"
using namespace std;
using namespace __gnu_pbds;
using Set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
void Assist(unsigned char *A, int N, int K, int R) {
int c[N], indo[N];
bool f[N] = {false};
int cur = 0, sz = 0;
Set pbd;
vector<pair<int, int>> bad;
int i;
for(i = 0;i < K;i++){
f[i] = true;
c[i] = i;
indo[i] = i;
if(A[cur++]){
sz++;
pbd.insert(i);
} else bad.emplace_back(i, i);
}
for(i = 0;i < N-1-bad.size();i++){
int r = GetRequest();
if(f[r]) {
if(!A[cur++]){
sz--;
pbd.erase(pbd.find(indo[r]));
bad.emplace_back(r, indo[r]);
}
continue;
}
if(!bad.empty()){
PutBack(bad.back().first);
int ind = bad.back().second;
f[r] = true;
f[bad.back().first] = false;
indo[r] = ind;
c[ind] = r;
bad.pop_back();
if(A[cur++]) {
sz++;
pbd.insert(ind);
} else bad.emplace_back(r, ind);
continue;
}
int pind = 0, L = log2(sz-1)+1;
for(int b = 0;b < L;b++) {
if(A[cur]) pind |= 1 << b;
cur++;
}
int ind = *pbd.find_by_order(pind);
PutBack(c[ind]);
f[r] = true;
f[c[ind]] = false;
c[ind] = r;
indo[r] = ind;
if(!A[cur++]){
sz--;
pbd.erase(pbd.find(ind));
bad.emplace_back(r, ind);
}
}
int r;
for(auto p : bad){
if(i == N-1) break;
i++;
r = GetRequest();
if(f[r]) continue;
PutBack(p.first);
f[r] = true;
f[p.first] = false;
}
r = GetRequest();
if(f[r]) return;
for(int i = 0;i < N;i++) if(f[i]) {
PutBack(i);
return;
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(i = 0;i < N-1-bad.size();i++){
| ~~^~~~~~~~~~~~~~~~
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(i = 0;i < N-1-bad.size();i++){
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
516 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
736 KB |
Output is correct |
4 |
Correct |
3 ms |
820 KB |
Output is correct |
5 |
Correct |
3 ms |
820 KB |
Output is correct |
6 |
Correct |
5 ms |
924 KB |
Output is correct |
7 |
Correct |
3 ms |
1016 KB |
Output is correct |
8 |
Correct |
3 ms |
948 KB |
Output is correct |
9 |
Correct |
5 ms |
984 KB |
Output is correct |
10 |
Correct |
5 ms |
948 KB |
Output is correct |
11 |
Correct |
4 ms |
948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1416 KB |
Output is correct |
2 |
Correct |
46 ms |
4408 KB |
Output is correct |
3 |
Correct |
92 ms |
11496 KB |
Output is correct |
4 |
Correct |
73 ms |
6756 KB |
Output is correct |
5 |
Correct |
91 ms |
7348 KB |
Output is correct |
6 |
Correct |
84 ms |
7444 KB |
Output is correct |
7 |
Correct |
78 ms |
8988 KB |
Output is correct |
8 |
Correct |
61 ms |
9032 KB |
Output is correct |
9 |
Correct |
90 ms |
7816 KB |
Output is correct |
10 |
Correct |
82 ms |
9628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
7560 KB |
Output is correct |
2 |
Correct |
78 ms |
8984 KB |
Output is correct |
3 |
Correct |
78 ms |
9156 KB |
Output is correct |
4 |
Correct |
92 ms |
9044 KB |
Output is correct |
5 |
Correct |
78 ms |
9004 KB |
Output is correct |
6 |
Correct |
81 ms |
9236 KB |
Output is correct |
7 |
Correct |
79 ms |
9268 KB |
Output is correct |
8 |
Correct |
91 ms |
9932 KB |
Output is correct |
9 |
Correct |
69 ms |
9812 KB |
Output is correct |
10 |
Correct |
82 ms |
9296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
936 KB |
Output is correct |
2 |
Correct |
3 ms |
1048 KB |
Output is correct |
3 |
Incorrect |
2 ms |
660 KB |
Error - advice is too long |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
8640 KB |
Output is correct - 118987 bits used |
2 |
Correct |
78 ms |
8920 KB |
Output is correct - 108451 bits used |
3 |
Correct |
82 ms |
8964 KB |
Output is correct - 109675 bits used |
4 |
Correct |
83 ms |
8988 KB |
Output is correct - 109722 bits used |
5 |
Correct |
79 ms |
9152 KB |
Output is correct - 109629 bits used |
6 |
Correct |
88 ms |
8952 KB |
Output is correct - 109566 bits used |
7 |
Correct |
81 ms |
8984 KB |
Output is correct - 109410 bits used |
8 |
Correct |
89 ms |
8916 KB |
Output is correct - 109657 bits used |
9 |
Correct |
80 ms |
8980 KB |
Output is correct - 109630 bits used |
10 |
Correct |
69 ms |
9680 KB |
Output is correct - 119778 bits used |