Submission #1199381

#TimeUsernameProblemLanguageResultExecution timeMemory
1199381TimDeeCave (IOI13_cave)C++20
100 / 100
349 ms572 KiB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0; i<n; ++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;

int ask(int q[]) {
  int x=tryCombination(q);
  if (x<0) x+=1e9;
  return x;
}
void exploreCave(int n) {
  int type[n], pos[n];
  int q[n];
  forn(i,n) pos[i]=type[i]=q[i]=0;
  vector<int> rev(n);
  vector<int> tip(n);
  forn(it,n) {
    forn(i,n) q[i]=0;
    forn(i,it) q[rev[i]]=tip[i];
    int x=ask(q);
    if (x > it) tip[it]=0;
    else tip[it]=1;
    int l=0, r=n-1;
    while (l<r) {
      int mid=(l+r)>>1;
      forn(i,n) q[i]=tip[it]^(i>mid);
      forn(i,it) q[rev[i]]=tip[i];
      int x=ask(q);
      if (x>it) r=mid;
      else l=mid+1;
    }
    pos[r]=it;
    type[r]=tip[it];
    rev[it]=r;
  }
  answer(type,pos);
}
#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...