#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
namespace {
int n;
vector<char> s;
}
void Anna(int N, std::vector<char> S) {
n=N;
s=S;
rep(x,0,n){
if (s[x]=='X') Send(0),Send(0);
if (s[x]=='Y') Send(0),Send(1);
if (s[x]=='Z') Send(1),Send(0);
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
namespace {
int n,l;
vector<int> bits;
string s;
} // namespace
void Bruno(int N, int L, std::vector<int> A) {
n=N,l=L,bits=A;
rep(x,0,n){
if (bits[2*x]==0 && bits[2*x+1]==0) s+='X';
if (bits[2*x]==0 && bits[2*x+1]==1) s+='Y';
if (bits[2*x]==1 && bits[2*x+1]==0) s+='Z';
}
//we want pattern like X Y Z Y X Y Z ...
vector<ii> v;
char c='Z';
rep(x,0,n) if (s[x]=='X' || s[x]=='Z'){
if (s[x]!=c) v.pub(ii(x,x)),c=s[x];
if (!v.empty()) v.back().se=x;
}
if (sz(v)%2==1) v.pob();
//for (auto &it:v) cout<<it.fi<<"_"<<it.se<<" "; cout<<endl;
vector<int> pos;
rep(x,0,sz(v)-1){
ll y=-1;
rep(xx,v[x].fi,v[x+1].se) if (s[xx]=='Y'){
y=xx;
break;
}
if (y!=-1) v[x+1].fi=max(v[x+1].fi,y+1);
pos.pub(v[x].fi);
pos.pub(y);
}
pos.pub(v.back().fi);
//for (auto &it:pos) cout<<it<<" "; cout<<endl;
rep(x,0,n){ //throw away useless guys
if (lb(all(pos),x)!=pos.end() && *lb(all(pos),x)!=x){
//cout<<x<<endl;
Remove(x);
}
}
while (sz(pos)>3){
//for (auto &it:pos) cout<<it<<" "; cout<<endl;
for (int x=1;x<sz(pos);x+=4){
if (pos[x]!=-1) Remove(pos[x]);
}
vector<int> npos;
for (int x=0;x<sz(pos);x+=8){
npos.pub(pos[x]);
if (x+2<sz(pos)){
if (x+2==sz(pos)-1){ //special case
npos.pub(-1);
npos.pub(pos[x+2]);
}
else{
Remove(pos[x+2]);
}
}
if (x+3<sz(pos)) npos.pub(pos[x+3]);
if (x+4<sz(pos)) Remove(pos[x+4]);
if (x+6<sz(pos)) npos.pub(pos[x+6]);
if (x+7<sz(pos)) npos.pub(pos[x+7]);
}
pos=npos;
}
if (pos[1]!=-1) Remove(pos[1]);
Remove(pos[0]);
Remove(pos[2]);
}
# |
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 |
88 ms |
9940 KB |
Wrong Answer [4] |
2 |
Halted |
0 ms |
0 KB |
- |