Submission #1032269

#TimeUsernameProblemLanguageResultExecution timeMemory
1032269Rafi22Ancient Machine (JOI21_ancient_machine)C++17
100 / 100
58 ms8956 KiB
#include "Anna.h"
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)

namespace {

	void code(vector<int>V)
	{
		vector<ll>fib(41);
		fib[0]=1;
		fib[1]=2;
		FOR(i,2,40) fib[i]=fib[i-1]+fib[i-2];
		ll x=0;
		ROF(i,39,0) if(V[i]) x+=fib[i];
		FOR(i,0,27)
		{
			if(x&(1<<i)) Send(1);
			else Send(0);
		}
	}
}

void Anna(int n,vector<char>S)
{
	int xd=n;
	FOR(i,0,n-1)
	{
		if(S[i]=='X')
		{
			xd=i;
			break;
		}
	}
	int m=100000;
	vector<int>a(m,0);
	if(xd<n-1)
	{
		a[xd]=1;
		FOR(i,xd+1,n-2) if(S[i]=='Z'&&(i==n-1||S[i+1]!='Z')) a[i+1]=1;
	}
	for(int i=0;i<m;i+=40)
	{
		vector<int>T;
		FOR(j,i,i+39) T.pb(a[j]);
		code(T);
	}
}
#include "Bruno.h"
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)

namespace {

}

void Bruno(int n,int l,vector<int>A)
{
	vector<ll>fib(41);
	fib[0]=1;
	fib[1]=2;
	FOR(i,2,40) fib[i]=fib[i-1]+fib[i-2];
	int m=100000;
	vector<int>a(m+1,0);
	int it=0;
	for(int i=0;i<sz(A);i+=28)
	{
		int x=0;
		FOR(j,0,27) if(A[i+j]) x+=(1<<j);
		ROF(j,39,0)
		{
			if(x>=fib[j])
			{
				x-=fib[j];
				a[it+j]=1;
			}
		}
		it+=40;
	}
	a[n]=1;
	int last=-1,k=-1;
	bool xd=0;
	FOR(i,0,n)
	{
		if(a[i])
		{
			if(!xd)
			{
				ROF(j,i,1) Remove(j-1);
				k=i+1;
				last=i+1;
				xd=1;
			}
			else
			{
				ROF(j,i-1,last+1) Remove(j-1);
				Remove(i-1);
				last=i;
			}
		}
	}
	if(k<=n) Remove(k-1);
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...