제출 #1163348

#제출 시각아이디문제언어결과실행 시간메모리
1163348boclobanchat동굴 (IOI13_cave)C++20
51 / 100
181 ms536 KiB
#include"cave.h"
#include<bits/stdc++.h>
using namespace std;
int tryCombination(int S[]);
void exploreCave(int N)
{
	int pos[N],A[N],ans[N];
	bool ck[N];
	for(int i=0;i<N;i++) ck[i]=true,pos[i]=0;
	for(int i=0;i<N;i++)
	{
		int l=0,r=N-1,p=-1,pp,pf=tryCombination(pos);
		if(pf==-1) pf=N+1;
		while(p<N-1) p++,pos[p]^=ck[p];
		int f=tryCombination(pos);
		if(f==-1) f=N+1;
		bool e=(pf<f);
		while(l<=r)
		{
			int mid=(l+r)/2;
			while(p<mid) p++,pos[p]^=ck[p];
			while(p>mid) pos[p]^=ck[p],p--;
			int res=tryCombination(pos);
			if(res==-1) res=N+1;
			if(e)
			{
				if(res!=pf) r=mid-1,pp=mid;
				else l=mid+1;
			}
			else
			{
				if(res==f) r=mid-1,pp=mid;
				else l=mid+1;
			}
		}
		while(p>=0) pos[p]^=ck[p],p--;
		ck[pp]=false;
		if(e) ans[pp]=pos[pp]=true;
		else ans[pp]=pos[pp]=false;
		A[pp]=i,pf=f;
	}
	answer(ans,A);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...