Submission #30027

#TimeUsernameProblemLanguageResultExecution timeMemory
30027kavunCave (IOI13_cave)C++14
100 / 100
418 ms640 KiB
#include "cave.h"
#include <bits/stdc++.h>

using namespace std;
int s[5010], d[5010], n;
bool mk[5010];

void change(int lo, int hi)
{
  int m = (lo + hi)/2;
  for(int i = lo; i <= m;i++)
    if(!mk[i])
      s[i] ^= 1;
}


void exploreCave(int N) {
  n = N;

  for(int i = 0; i < N; i++)
    {
      int lo = 0, hi = n-1;
      int ps = tryCombination(s);
      int open = i < ps || ps == -1 ? 0 : 1;
      int after;
      while(lo != hi)
	{
	  int m = (lo + hi) / 2;
	  change(lo,hi);
	  int pos = tryCombination(s);
	  after = i < pos || pos == -1 ? 0 : 1;
	  change(lo,hi);
	  if(open != after)
	    hi = m;
	  else
	    lo = m+1;
	}
      mk[lo] = true;
      s[lo] = open;
      d[lo] = i;
    }
  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...