This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "cave.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back
int nn;
void toggle(int S[], int done[], int l, int r) {
for (int i = l; i <= r; ++i) {
if (done[i] == -1) S[i] ^= 1;
}
}
void rec(int l, int r, int idx, int S[], int done[]) {
if (r == l) {
// cout << l << " WOW " << idx << END;
done[l] = idx;
int cur = tryCombination(S);
if (cur == idx) S[l] ^= 1;
// cout << "DONE ARRAY: ";
// for (int i = 0; i < nn; ++i) cout << done[i] << " ";
// cout << END;
return;
}
int cur = tryCombination(S);
bool open = false;
if (cur > idx || cur == -1) open = true;
// cout << idx << " " << l << " " << r << " " << cur << " " << open << ":\n";
// for (int i = 0; i < nn; ++i) cout << S[i] << " ";
// cout << END;
int mid = (l + r) >> 1;
toggle(S, done, l, mid);
int nxt = tryCombination(S);
bool topen = false;
if (nxt > idx || nxt == -1) topen = true;
// cout << idx << " " << l << " " << r << " " << nxt << " " << topen << ":\n";
// for (int i = 0; i < nn; ++i) cout << S[i] << " ";
// cout << END;
if (open == topen) rec(mid + 1, r, idx, S, done);
else rec(l, mid, idx, S, done);
}
void exploreCave(int n) {
nn = n;
int S[n] = {0}, D[n] = {-1};
for (int i = 0; i < n; ++i) S[i] = 0, D[i] = -1;
for (int i = 0; i < n; ++i) {
rec(0, n - 1, i, S, D);
}
// for (int i = 0; i < n; ++i) cout << D[i] << " ";
// cout << END;
answer(S, D);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |