Submission #412419

#TimeUsernameProblemLanguageResultExecution timeMemory
412419albertolg101Cave (IOI13_cave)C++17
100 / 100
815 ms452 KiB
#include<bits/stdc++.h>
#include "cave.h"

using namespace std;

void exploreCave (int n)
{
	int s[n], d[n];

	for(int i = 0 ; i < n ; i++)
	{
		s[i] = 0 ;
		d[i] = -1;
	}

	for(int i = 0 ; i < n ; i++)
	{
		int test[n];

		for(int j = 0 ; j < n ; j++)
		{
			if(d[j] != -1)
				test[j] = s[j];
			else
				test[j] = 0;
		}

		bool sol = (tryCombination(test) == i);

		/*
		for(int i = 0 ; i < n ; i++)
			cout << test[i] << ' ' ; 
		cout << endl ;
		cout << tryCombination(test) << ' ' << sol << ' '  ; 
		cout << endl ;
		*/

		int pos = -1;

		for(int j = 13 ; j >= 0 ; j--)
		{
			int target = pos + (1<<j);

			if(target >= n)
				continue ;

			for(int k = 0 ; k < n ; k++)
			{
				if(d[k] != -1)
					test[k] = s[k];

				else
				{
					(k < target ? test[k] = 1 : test[k] = 0);
				}
			}

			if((tryCombination(test) == i) == sol)
				pos = target;
			/*
			for(int i = 0 ; i < n ; i++)
				cout << test[i] << ' ' ; 
			cout << ": " << tryCombination(test) << ' ' << target << ' ' << pos << endl ;
			*/
		}

		//cout << pos << endl ;

		d[pos] = i;
		s[pos] = sol;
	}

	//cout << endl ;

	answer(s, d);
}
#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...