제출 #339074

#제출 시각아이디문제언어결과실행 시간메모리
339074markussie동굴 (IOI13_cave)C++17
13 / 100
139 ms492 KiB
#include "cave.h"
#include <vector>
#include <algorithm>

using namespace std;

const int mxn = 5e3;

void exploreCave(int n)
{
  vector<int> to(n, -1);
  vector<int> pos(n, -1);

  for(int i = 0; i < n; ++i)
    {
      vector<int> attemp(n, 0);
      for(int j = 0; j < n; ++j)
	if(pos[j] != -1)
	  attemp[j] = pos[j];
      int opened = tryCombination(attemp.data());
      int type = -1;
      if(opened == -1)
	{
	  pos = attemp;
	  break;
	}
      else
	type = opened == i;
      
      int l = 0, r = n;
      while(r - l > 1)
	{
	  int mid = (l + r) / 2;
	  for(int j = l; j < r; ++j)
	    if(pos[j] != -1)
	      attemp[j] = pos[j];
	    else
	      attemp[j] = type ^ (j >= mid);

	  opened = tryCombination(attemp.data());
	  if(opened == -1)
	    {
	      pos = attemp;
	      break;
	    }
	  if(opened == i)
	    l = mid;
	  else
	    r = mid;
	}
      pos[l] = type;
      to[l] = i;
     }
  
  for(int i = 0; i < n; ++i)
    {
      if(to[i] == -1)
	{
	  pos[i] = pos[i] ^ 1;
	  to[i] = tryCombination(pos.data());
	  pos[i] = pos[i] ^ 1;
	}
    }
  answer(pos.data(), to.data());
}
#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...