답안 #417295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417295 2021-06-03T14:31:37 Z errorgorn Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
85 ms 9984 KB
#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;
	if (sz(v)){
		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);
		}
	}
	
	if (pos.empty()) return;
	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;
	}
	
	assert(sz(pos)==3);
	
	if (pos[1]!=-1) Remove(pos[1]);
	Remove(pos[0]);
	Remove(pos[2]);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 484 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 9984 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -