#include "Anna.h"
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
using ll = long long;
const ll mod=1e9+7;
void Anna(int n, vector<char> s)
{
for(int i = 0; i < n; i++)
if(s[i]=='X') Send(0), Send(0);
else if(s[i]=='Y') Send(0), Send(1);
else Send(1), Send(0);
}
#include "Bruno.h"
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
using ll = long long;
const ll mod=1e9+7;
void Bruno(int n, int l, vector<int> a)
{
vector<char> s;
for(int i = 0; i < n; i++)
{
int x=0;
if(a[i*2]) x+=2;
if(a[i*2+1]) x++;
if(x==0) s.emplace_back('X');
else if(x==1) s.emplace_back('Y');
else s.emplace_back('Z');
}
int dp[1<<19], trace[1<<19];
for(int i = 0; i < (1<<n); i++)
dp[i]=-inf;
dp[0]=0;
for(int mask = 0; mask < (1<<n); mask++)
{
for(int i = 0; i < n; i++)
{
if(mask>>i&1) continue;
int l=-1, r=n;
for(int j = i-1; j >= 0; j--)
if(!(mask>>j&1))
{
l=j;
break;
}
for(int j = i+1; j < n; j++)
if(!(mask>>j&1))
{
r=j;
break;
}
int cost=0;
if(l>=0 && r<n && s[i]=='Y' && s[l]=='X' && s[r]=='Z')
cost=1;
if(dp[mask]+cost>dp[mask|(1<<i)])
dp[mask|(1<<i)]=dp[mask]+cost, trace[mask|(1<<i)]=mask;
}
}
int mask=(1<<n)-1;
vector<int> path;
path.clear();
while(mask!=0)
{
int nxt=trace[mask];
int sus=(nxt^mask), pos;
for(int i = 0; i < n; i++)
if((1<<i)==sus)
pos=i;
path.emplace_back(pos);
mask=nxt;
}
reverse(path.begin(), path.end());
for(int c:path) Remove(c);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |