# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1125548 | Lemser | Cave (IOI13_cave) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
// #define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)
bool cmin(ll &a, ll b) { if(b<a){a=b;return 1;}return 0; }
bool cmax(ll &a, ll b) { if(b>a){a=b;return 1;}return 0; }
void valid(ll in) { cout<<((in)?"YES\n":"NO\n"); }
ll lcm(ll a, ll b) { return (a/gcd(a,b))*b; }
ll gauss(ll n) { return (n*(n+1))/2; }
void exploreCave(int n) {
int s[n], d[n], tos[n], qs[n], nqs[n];
fo (i, n) s[i] = d[i] = tos[i] = qs[i] = 0;
fo (i, n) {
set<ll> st;
fo (j, n) qs[j] = 0l, st.insert(j);
fo (j, i) qs[tos[j]] = s[tos[j]], st.erase(tos[j]);
ll idx = tryCombination(qs), w = 0;
if (idx == j) w = 1;
ll l = 0, r = sz(st)-1;
while (l <= r) {
ll m = (l+r)/2;
fo (j, n) nqs[j] = qs[j];
ll j = 0;
for (ll swt: st) {
if (j > m) nqs[swt] = w^1;
else nqs[swt] = w;
j++;
}
idx = tryCombination(nqs);
if (idx > j) r = m-1;
else l = m+1;
}
ll whswt = 0, j = 0;
for (ll swt: st) {
if (j == l) { whst = swt; break; }
j++;
}
tos[j] = whswt;
s[tos[j]] = w;
}
fo (i, n) d[tos[i]] = i;
answer(s, d);
}
// void test_case () {
// }
// int main() {
// cin.tie(0)->sync_with_stdio(0);
// int tt = 1;
// cin >> tt;
// while (tt--) test_case();
// }