# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1199375 | TimDee | 동굴 (IOI13_cave) | C++20 | 0 ms | 0 KiB |
#include "grader.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);
}