#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);
void Send(int);
#endif
void Anna(int N, std::vector<char> S) {
vector<int> X, Y, Z;
int s=N, e=0, p, mb=7, mbc=1e7;
for(int i=0;i<N;i++) {
if(S[i]=='X') s=min(s,i);
else if(S[i]=='Z') e=i;
}
if(s>=e) 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);
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);
}
}
p=s-1;
for(auto y: Y) Send(S[(p+=y+2)+1]=='Z');
}
#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);
void Send(int);
#endif
void Bruno(int N, int L, std::vector<int> A) {
int s=0, e=0, j=0, mb=0, p, ysz=0;
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++];
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;
for(int i=0;i<N;i++) S[i]='?';
S[s]='X'; S[e]='Z'; 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);
}
for(auto y: Y) S[y+1]=A[j++] ? 'Z':'X';
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();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
484 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
0 ms |
484 KB |
Output is correct |
5 |
Correct |
0 ms |
496 KB |
Output is correct |
6 |
Correct |
0 ms |
484 KB |
Output is correct |
7 |
Correct |
0 ms |
484 KB |
Output is correct |
8 |
Correct |
0 ms |
492 KB |
Output is correct |
9 |
Correct |
0 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
484 KB |
Output is correct |
11 |
Correct |
0 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
74 ms |
8120 KB |
Partially correct |
2 |
Partially correct |
74 ms |
8184 KB |
Partially correct |
3 |
Partially correct |
78 ms |
8092 KB |
Partially correct |
4 |
Partially correct |
76 ms |
8180 KB |
Partially correct |
5 |
Partially correct |
76 ms |
8096 KB |
Partially correct |
6 |
Partially correct |
77 ms |
8112 KB |
Partially correct |
7 |
Partially correct |
74 ms |
8096 KB |
Partially correct |
8 |
Partially correct |
75 ms |
8096 KB |
Partially correct |
9 |
Partially correct |
76 ms |
8168 KB |
Partially correct |
10 |
Partially correct |
74 ms |
8092 KB |
Partially correct |
11 |
Partially correct |
76 ms |
8164 KB |
Partially correct |
12 |
Partially correct |
76 ms |
8088 KB |
Partially correct |
13 |
Partially correct |
77 ms |
8464 KB |
Partially correct |
14 |
Partially correct |
72 ms |
8112 KB |
Partially correct |
15 |
Partially correct |
65 ms |
8064 KB |
Partially correct |
16 |
Partially correct |
66 ms |
8252 KB |
Partially correct |
17 |
Correct |
49 ms |
6356 KB |
Output is correct |
18 |
Correct |
49 ms |
6384 KB |
Output is correct |
19 |
Correct |
49 ms |
6420 KB |
Output is correct |
20 |
Partially correct |
65 ms |
8272 KB |
Partially correct |
21 |
Partially correct |
65 ms |
8360 KB |
Partially correct |
22 |
Correct |
55 ms |
6428 KB |
Output is correct |
23 |
Partially correct |
67 ms |
8156 KB |
Partially correct |
24 |
Partially correct |
67 ms |
8568 KB |
Partially correct |
25 |
Correct |
53 ms |
6756 KB |
Output is correct |
26 |
Correct |
51 ms |
6756 KB |
Output is correct |
27 |
Correct |
49 ms |
6672 KB |
Output is correct |
28 |
Correct |
51 ms |
6668 KB |
Output is correct |
29 |
Correct |
51 ms |
6768 KB |
Output is correct |
30 |
Correct |
51 ms |
6632 KB |
Output is correct |
31 |
Correct |
49 ms |
6640 KB |
Output is correct |
32 |
Partially correct |
73 ms |
8516 KB |
Partially correct |
33 |
Partially correct |
73 ms |
8572 KB |
Partially correct |