# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
971257 | aryanc403 | Cave (IOI13_cave) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Compete against Yourself.
Author - Aryan (@aryanc403)
*/
/*
Credits -
Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
https://codeforces.com/contest/4/submission/150120627
*/
#ifdef ARYANC403
#include <header.h>
#else
#pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target ("sse,sse2,mmx")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define dbg(args...) 42;
#define endl "\n"
#endif
// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
Fun fun_;
public:
template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
using namespace std;
#define fo(i,n) for(i=0;i<(n);++i)
#define repA(i,j,n) for(i=(j);i<=(n);++i)
#define repD(i,j,n) for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second
using lli = int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;
template <class T>
using ordered_set = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.
// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;
const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
cerr<<"Time Taken : "<<diff.count()<<"\n";
}
int tryCombination(int S[]);
void answer(int S[], int D[]);
void exploreCave(const lli N){
int S[N],D[N];
for(lli j=0;j<N;j++){
S[j]=0;
D[j]=-1;
}
set<lli> rem;
for(lli j=0;j<N;j++)
rem.insert(j);
auto getIdx=[&](const lli idx)->ii{
bool def = 0;
auto chk=[&](const lli mid)->bool{
for(const auto &j:rem)
S[j]=!def;
for(const auto &j:rem){
if(j>mid)
break;
S[j]=def;
}
const lli dr = tryCombination(S);
return dr==-1||dr>idx;
};
if(!chk(N))
def=1;
lli l=-1,r=N;
while(r-l>1){
const lli mid = (l+r)/2;
if(chk(mid))
r=mid;
else
l=mid;
}
// dbg(idx,r,def);
return {r,def};
};
for(lli j=0;j<N;j++){
const auto resp = getIdx(j);
D[resp.X]=j;
S[resp.X]=resp.Y;
rem.erase(resp.X);
}
// dbg("ans",prt(N,S));
// dbg("ans",prt(N,D));
answer(S,D);
}