#include "Anna.h"
#include "bits/stdc++.h"
using namespace std;
#define ar array
void Anna(int n, vector<char> s) {
vector<int> res(n), pref(n), suff(n + 1);
int c=0;
for(int i=0;i<n;i++){
if(i) pref[i] = pref[i-1];
if(s[i] == 'Y' && c) pref[i]++, c = 0;
if(s[i] == 'X') c++;
}
c=0;
for(int i=n-1;~i;i--){
suff[i] = suff[i+1];
if(s[i] == 'Y' && c) suff[i]++;
if(s[i] == 'Z') c++;
}
ar<int, 2> r = {suff[0], 0};
for(int i=0;i<n;i++){
if(s[i] == 'Z') r = max(r, {pref[i] + suff[i+1], i + 1});
}
c=-1;
for(int i=r[1]-1,is=0;~i;i--){
if(!is && s[i] == 'Z') res[i] = 1, is = 1;
if(s[i] == 'Y') c = i;
if(s[i] == 'X' && ~c) res[i] = res[c] = 1, c = -1;
}
c=-1;
for(int i=r[1],is=0;i<n;i++){
if(!is && s[i] == 'X') res[i] = 1, is = 1;
if(s[i] == 'Y') c = i;
if(s[i] == 'Z' && ~c) res[i] = res[c] = 1, c = -1;
}
for(int j=0;j<20;j++) Send(r[1] >> j & 1);
for(int i=0;i<n;i++) Send(res[i]);
}
#include "Bruno.h"
#include "bits/stdc++.h"
using namespace std;
void Bruno(int n, int l, vector<int> a) {
int x=0;
for(int i=0;i<20;i++) x |= (a[i] << i);
a.erase(a.begin(), a.begin() + 20);
auto add = [&](int l, int r){
for(int i=l;i<=r;i++) Remove(i);
};
vector<int> tot;
for(int i=x-1;~i;i--){
if(a[i]){
tot.push_back(i);
}
}
int lx = 0;
if(!tot.empty()){
for(int i=2;i<(int)tot.size();i+=2){
add(tot[i-1] + 1, tot[i-2] - 1);
add(tot[i] + 1, tot[i-1] - 1);
Remove(tot[i-1]);
Remove(tot[i]);
} add(0, tot.back() - 1);
lx = tot[0];
tot.clear();
}
for(int i=x;i<n;i++){
if(a[i]){
tot.push_back(i);
}
}
if(!tot.empty()){
for(int i=2;i<(int)tot.size();i++){
add(tot[i-2] + 1, tot[i-1] - 1);
add(tot[i-1] + 1, tot[i] - 1);
Remove(tot[i-1]);
Remove(tot[i]);
} add(tot.back() + 1, n - 1);
add(lx, tot[0]);
} else add(lx, n - 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
484 KB |
Wrong Answer [4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
4216 KB |
Wrong Answer [4] |
2 |
Halted |
0 ms |
0 KB |
- |