Submission #672743

#TimeUsernameProblemLanguageResultExecution timeMemory
672743Hacv16Cave (IOI13_cave)C++17
0 / 100
250 ms392 KiB
#include<bits/stdc++.h>
#include "cave.h"

using namespace std;
 
typedef long long ll;
const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;

int n, S[MAX], D[MAX];
bool mark[MAX];

bool f(int x, int j, int c){
	for(int i = 0; i < x; i++) if(!mark[i]) S[i] = c;
	for(int i = x; i < n; i++) if(!mark[i]) S[i] = !c;

	int query = tryCombination(S);
	return (query != j);
}

void exploreCave(int n_){
	n = n_;

	for(int door = 0; door < n; door++){	
		for(int i = 0; i < n; i++)
			if(!mark[i]) S[i] = 0;

		int color = (tryCombination(S) == door);
		int l = 0, r = n, pos = -1;

		while(l <= r){
			int m = (l + r) >> 1;
			if(f(m, door, color)) r = m - 1, pos = m;
			else l = m + 1;
		}

		assert(pos != -1);

		mark[pos] = true;

		D[pos] = door;
		S[pos] = color;
	}

	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...