Submission #1254181

#TimeUsernameProblemLanguageResultExecution timeMemory
1254181ifugaoLight Bulbs (EGOI24_lightbulbs)C++20
57.44 / 100
34 ms420 KiB
#include <bits/stdc++.h>

using namespace std;

int N;
string allZero;

int test_row(int rowId,string& choice)
{
	cout << "?" << endl;
	for(int i=0;i<N;i++)
	{
		if(i==rowId)
			cout << choice << endl;
		else
			cout << allZero << endl;
	}
	int litCells;
	cin >> litCells;
	return litCells;
}

int test_horizontal_aux(int row1,int row2, int col)
{
	cout << "?" << endl;
	for(int i=0;i<N;i++)
	{
		if(i==row1 || i==row2)
		{
			allZero[col]='1';
			cout << allZero << endl;
			allZero[col]='0';
		}
		else
			cout << allZero << endl;
	}
	int litCells;
	cin >> litCells;
	return litCells;
}

bool test_horizontal(int row,int col)
{
	for(int offset=1;offset<=2;offset++)
	{
		int litCells=test_horizontal_aux(row,(row+offset)%N,col);
		if(litCells==2*N)
			return true;
		else if(litCells==N)
			return false;
	}
	int litCells=test_horizontal_aux((row+1)%N,(row+2)%N,col);
	if(litCells==2*N)
		return false;
	else if(litCells==N)
		return true;
	assert(false);
}

void full_row(int rowId)
{
	cout << "!" << endl;
	for(int i=0;i<N;i++)
	{
		if(i==rowId)
			cout << string(N,'1') << endl;
		else
			cout << allZero << endl;
	}
}

void print_picked(vector<int>& picked)
{
	cout << "!" << endl;
	for(int i=0;i<N;i++)
	{
		allZero[picked[i]]='1';
		cout << allZero << endl;
		allZero[picked[i]]='0';
	}
}

int cut_half(int cnt,string& choice,string& prevChoice)
{
	int curCnt=0;
	for(int j=0;j<N;j++)
	{
		if(prevChoice[j]=='1' && curCnt<(cnt+1)/2)
		{
			choice[j]='1';
			curCnt++;
		}
		else
			choice[j]='0';
	}
	return curCnt;
}

void other_half(int& curCnt,string& choice,string& prevChoice)
{
	curCnt=0;
	for(int j=0;j<N;j++)
	{
		if(prevChoice[j]=='1' && choice[j]=='0')
		{
			choice[j]='1';
			curCnt++;
		}
		else
			choice[j]='0';
	}
}

int main()
{
	cin >> N;
	allZero=string(N,'0');
	vector<int> picked(N,-1);
	for(int i=0;i<N;i++)
	{
		// Try whole row
		string choice(N,'1');
		string prevChoice=choice;
		int cnt=N;
		int litCells=test_row(i,choice);
		if(litCells==N*N)
		{
			full_row(i);
			exit(0);
		}
		while(cnt>1)
		{
			int curCnt=cut_half(cnt,choice,prevChoice);
			if(curCnt==1)
			{
				int col=choice.find('1');
				if(test_horizontal(i,col))
				{
					picked[i]=col;
					break;
				}
				else
				{
					other_half(curCnt,choice,prevChoice);
				}
			}
			else
			{
				litCells=test_row(i,choice);
				if(litCells==N)
				{
					picked[i]=choice.find('1');
					break;
				}
				else if(litCells==N*curCnt)
				{
					other_half(curCnt,choice,prevChoice);
				}
			}
			prevChoice=choice;
			cnt=curCnt;
		}
		if(cnt==1)
			picked[i]=prevChoice.find('1');
		else
			assert(picked[i]!=-1);
	}
	print_picked(picked);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...