Submission #346660

#TimeUsernameProblemLanguageResultExecution timeMemory
346660PetyCave (IOI13_cave)C++14
100 / 100
1329 ms748 KiB
#include <bits/stdc++.h>
#include "cave.h"

using namespace std;

const int M = 5000;

bool found[M + 2];
int Switch[M + 2], query[M + 2], s[M + 2], d[M + 2];

int ask (int n, int mij, int state) {
   for (int i = 0; i < n; i++)
    if (found[i])
      query[i] = Switch[i];
    else if (i <= mij)
      query[i] = state;
    else
      query[i] = 1 - state;
  return tryCombination(query);
}

void exploreCave (int n) {
  for (int i = 0; i < n; i++) {
    bool state;
    int value = ask(n, n - 1, 1);
    if (value > i || value == -1)
      state = 1;
    else
      state = 0;
    int st = 0, dr = n - 1, poz = 0;
    while (st <= dr) {
      int mij = (st + dr) / 2;
      int aux = ask(n, mij, state);
      if (aux > i || aux == -1) {
        dr = mij - 1;
        poz = mij;
      }
      else
        st = mij + 1;
    }
    d[poz] = i;
    s[poz] = state;
    found[poz] = 1;
    Switch[poz] = state;
  }
  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...