Submission #106615

#TimeUsernameProblemLanguageResultExecution timeMemory
106615hugo_pmCave (IOI13_cave)C++17
100 / 100
1138 ms552 KiB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;

#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int nbBlocs;
const int maxPortes = 5005;
int bloc[maxPortes];
int blocToPorte[maxPortes];

void det(int i)
{
	int rt = tryCombination(bloc);
	bool w = (rt == i);
	int l = 0, r = nbBlocs-1;
	while (l < r) {
		int m = (l+r) / 2;
		form(w, m+1) {
			if (blocToPorte[w] == -1) bloc[w] ^= 1;
		}
		bool rd = (tryCombination(bloc) == i);
		bool change = rd^w;
		if (change) { r=m; }
		else { l=m+1; }	
		form(w, m+1) if (blocToPorte[w] == -1) bloc[w] ^= 1;
	}

	blocToPorte[l] = i;
	if (rt == i) bloc[l] ^= 1;
}

void exploreCave(int N)
{
	fill_n(&blocToPorte[0], 5005, -1);
	nbBlocs = N;
	form(i, N) det(i);
	answer(bloc, blocToPorte);
}
#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...