#include "Anna.h"
#include <bits/stdc++.h>
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
using namespace std;
#ifdef NON_SUBMIT
void Remove(int a) {}
void Send(int a) {}
#endif
void Anna(int N, std::vector<char> S) {
vector<int> X, Y, Z;
int s=N, e=0, p, mb=7, mbc=2*N;
for(int i=0;i<N;i++) {
if(S[i]=='X') s=min(s,i);
else if(S[i]=='Y') e=i;
}
if(s>=e) {
//for(int i=0;i<N;i++) Send(0);
return;
}
for(int i=17;--i>=0;) Send(s&(1<<i) ? 1:0);
for(int i=17;--i>=0;) Send(e&(1<<i) ? 1:0);
p=s-1;
for(int i=s+1;i<e;i++) if(S[i]=='Y' && S[i+1]!='Y') {
(S[i+1]=='X' ? X:Z).push_back(Y.size());
Y.push_back(i-p-2);
p=i;
}
for(int t=7;--t;) {
int c=0;
for(auto y: Y) c+=y<(1<<t)-1;
if(mbc>c*t+(N-c)*(t+17)) {
mbc=c*t+(N-c)*(t+17);
mb=t;
}
}
for(int i=3;--i>=0;) Send(mb&(1<<i) ? 1:0);
Send(X.size()>Z.size());
for(int i=16;--i>=0;) Send(Y.size()&(1<<i) ? 1:0);
for(auto y: Y) {
if(y<(1<<mb)-1) {
for(int i=mb;--i>=0;) Send(y&(1<<i) ? 1:0);
}
else {
for(int i=0;i<mb;i++) Send(1);
for(int i=17;--i>=0;) Send(y&(1<<i) ? 1:0);
}
}
if(X.size()>Z.size()) swap(X,Z);
for(int i=X.size();--i;) X[i]-=X[i-1]+1;
mb=7; mbc=2*N;
for(int t=7;--t;) {
int c=0;
for(auto x: X) c+=x<(1<<t)-1;
if(mbc>c*t+(N-c)*(t+15)) {
mbc=c*t+(N-c)*(t+15);
mb=t;
}
}
for(int i=3;--i>=0;) Send(mb&(1<<i) ? 1:0);
for(auto x: X) {
if(x<(1<<mb)-1) {
for(int i=mb;--i>=0;) Send(x&(1<<i) ? 1:0);
}
else {
for(int i=0;i<mb;i++) Send(1);
for(int i=15;--i>=0;) Send(x&(1<<i) ? 1:0);
}
}
}
void Bruno(int N, int L, std::vector<int> A) {
int s=0, e=0, j=0, mb=0, p=-1, ysz=0;
char ch;
if(L==0) {
for(int i=0;i<N;i++) Remove(i);
return;
}
for(int i=0;i<17;i++) s=2*s+A[j++];
for(int i=0;i<17;i++) e=2*e+A[j++];
for(int i=0;i<3;i++) mb=2*mb+A[j++];
ch=A[j++] ? 'Z':'X';
for(int i=0;i<16;i++) ysz=2*ysz+A[j++];
if(ysz==0) {
for(int i=0;i<N;i++) Remove(i);
return;
}
vector<char> S(N);
vector<int> I, Y;
S[s]='X'; S[e]='Z';
for(int i=0;i<N;i++) S[i]='?';
p=s-1;
while(ysz--) {
int v=0;
for(int i=0;i<mb;i++) v=2*v+A[j++];
if(v==(1<<mb)-1) {
for(int i=v=0;i<17;i++) v=2*v+A[j++];
}
S[p+=v+2]='Y';
Y.push_back(p);
}
p=-1; mb=0;
for(int i=0;i<3;i++) mb=2*mb+A[j++];
while(j<L) {
int v=0;
for(int i=0;i<mb;i++) v=2*v+A[j++];
if(v==(1<<mb)-1) {
for(int i=v=0;i<15;i++) v=2*v+A[j++];
}
S[Y[p+=v+1]+1]=ch;
}
ch=(int)'X'+'Z'-ch;
for(auto y: Y) if(S[y+1]=='?') S[y+1]=ch;
for(int i=0;i<N;i++) {
if(S[i]=='?') Remove(i);
else if(S[i]=='Y') p=i+1;
}
if(p<e) {
Remove(p);
S[p]='?';
}
for(int i=0;i<N;i++) if(S[i]!='?') {
if(S[i]=='Z') {
for(;;) {
Remove(I.back());
I.pop_back();
if(I.size()==1) {
Remove(i);
break;
}
Remove(I.back());
I.pop_back();
}
}
else I.push_back(i);
}
while(I.size()) {
Remove(I.back());
I.pop_back();
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
using namespace std;
#ifdef NON_SUBMIT
void Remove(int a) {}
void Send(int a) {}
#endif
void Anna(int N, std::vector<char> S) {
vector<int> X, Y, Z;
int s=N, e=0, p, mb=7, mbc=2*N;
for(int i=0;i<N;i++) {
if(S[i]=='X') s=min(s,i);
else if(S[i]=='Y') e=i;
}
if(s>=e) {
//for(int i=0;i<N;i++) Send(0);
return;
}
for(int i=17;--i>=0;) Send(s&(1<<i) ? 1:0);
for(int i=17;--i>=0;) Send(e&(1<<i) ? 1:0);
p=s-1;
for(int i=s+1;i<e;i++) if(S[i]=='Y' && S[i+1]!='Y') {
(S[i+1]=='X' ? X:Z).push_back(Y.size());
Y.push_back(i-p-2);
p=i;
}
for(int t=7;--t;) {
int c=0;
for(auto y: Y) c+=y<(1<<t)-1;
if(mbc>c*t+(N-c)*(t+17)) {
mbc=c*t+(N-c)*(t+17);
mb=t;
}
}
for(int i=3;--i>=0;) Send(mb&(1<<i) ? 1:0);
Send(X.size()>Z.size());
for(int i=16;--i>=0;) Send(Y.size()&(1<<i) ? 1:0);
for(auto y: Y) {
if(y<(1<<mb)-1) {
for(int i=mb;--i>=0;) Send(y&(1<<i) ? 1:0);
}
else {
for(int i=0;i<mb;i++) Send(1);
for(int i=17;--i>=0;) Send(y&(1<<i) ? 1:0);
}
}
if(X.size()>Z.size()) swap(X,Z);
for(int i=X.size();--i;) X[i]-=X[i-1]+1;
mb=7; mbc=2*N;
for(int t=7;--t;) {
int c=0;
for(auto x: X) c+=x<(1<<t)-1;
if(mbc>c*t+(N-c)*(t+15)) {
mbc=c*t+(N-c)*(t+15);
mb=t;
}
}
for(int i=3;--i>=0;) Send(mb&(1<<i) ? 1:0);
for(auto x: X) {
if(x<(1<<mb)-1) {
for(int i=mb;--i>=0;) Send(x&(1<<i) ? 1:0);
}
else {
for(int i=0;i<mb;i++) Send(1);
for(int i=15;--i>=0;) Send(x&(1<<i) ? 1:0);
}
}
}
void Bruno(int N, int L, std::vector<int> A) {
int s=0, e=0, j=0, mb=0, p=-1, ysz=0;
char ch;
if(L==0) {
for(int i=0;i<N;i++) Remove(i);
return;
}
for(int i=0;i<17;i++) s=2*s+A[j++];
for(int i=0;i<17;i++) e=2*e+A[j++];
for(int i=0;i<3;i++) mb=2*mb+A[j++];
ch=A[j++] ? 'Z':'X';
for(int i=0;i<16;i++) ysz=2*ysz+A[j++];
if(ysz==0) {
for(int i=0;i<N;i++) Remove(i);
return;
}
vector<char> S(N);
vector<int> I, Y;
S[s]='X'; S[e]='Z';
for(int i=0;i<N;i++) S[i]='?';
p=s-1;
while(ysz--) {
int v=0;
for(int i=0;i<mb;i++) v=2*v+A[j++];
if(v==(1<<mb)-1) {
for(int i=v=0;i<17;i++) v=2*v+A[j++];
}
S[p+=v+2]='Y';
Y.push_back(p);
}
p=-1; mb=0;
for(int i=0;i<3;i++) mb=2*mb+A[j++];
while(j<L) {
int v=0;
for(int i=0;i<mb;i++) v=2*v+A[j++];
if(v==(1<<mb)-1) {
for(int i=v=0;i<15;i++) v=2*v+A[j++];
}
S[Y[p+=v+1]+1]=ch;
}
ch=(int)'X'+'Z'-ch;
for(auto y: Y) if(S[y+1]=='?') S[y+1]=ch;
for(int i=0;i<N;i++) {
if(S[i]=='?') Remove(i);
else if(S[i]=='Y') p=i+1;
}
if(p<e) {
Remove(p);
S[p]='?';
}
for(int i=0;i<N;i++) if(S[i]!='?') {
if(S[i]=='Z') {
for(;;) {
Remove(I.back());
I.pop_back();
if(I.size()==1) {
Remove(i);
break;
}
Remove(I.back());
I.pop_back();
}
}
else I.push_back(i);
}
while(I.size()) {
Remove(I.back());
I.pop_back();
}
}
Compilation message
Anna.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Anna.cpp:85:24: error: 'Remove' was not declared in this scope; did you mean 'remove'?
85 | for(int i=0;i<N;i++) Remove(i);
| ^~~~~~
| remove
Anna.cpp:94:24: error: 'Remove' was not declared in this scope; did you mean 'remove'?
94 | for(int i=0;i<N;i++) Remove(i);
| ^~~~~~
| remove
Anna.cpp:124:17: error: 'Remove' was not declared in this scope; did you mean 'remove'?
124 | if(S[i]=='?') Remove(i);
| ^~~~~~
| remove
Anna.cpp:128:3: error: 'Remove' was not declared in this scope; did you mean 'remove'?
128 | Remove(p);
| ^~~~~~
| remove
Anna.cpp:134:5: error: 'Remove' was not declared in this scope; did you mean 'remove'?
134 | Remove(I.back());
| ^~~~~~
| remove
Anna.cpp:147:3: error: 'Remove' was not declared in this scope; did you mean 'remove'?
147 | Remove(I.back());
| ^~~~~~
| remove
Bruno.cpp: In function 'void Anna(int, std::vector<char>)':
Bruno.cpp:30:24: error: 'Send' was not declared in this scope
30 | for(int i=17;--i>=0;) Send(s&(1<<i) ? 1:0);
| ^~~~
Bruno.cpp:31:24: error: 'Send' was not declared in this scope
31 | for(int i=17;--i>=0;) Send(e&(1<<i) ? 1:0);
| ^~~~
Bruno.cpp:46:23: error: 'Send' was not declared in this scope
46 | for(int i=3;--i>=0;) Send(mb&(1<<i) ? 1:0);
| ^~~~
Bruno.cpp:47:2: error: 'Send' was not declared in this scope
47 | Send(X.size()>Z.size());
| ^~~~