#include "cave.h"
#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define ld long double
#define iloop(m, h) for (ll i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define iloop_(m, h, g) for (auto i = m; i != h; i += g)
#define jloop_(m, h, g) for (auto j = m; j != h; j += g)
#define kloop_(m, h, g) for (auto k = m; k != h; k += g)
#define lloop_(m, h, g) for (auto l = m; l != h; l += g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
void exploreCave(int N) {
int a[N];
int det[N];
int ans[N], ans2[N];
memset(det, -1, sizeof(det));
iloop(0, N) {
bool main = 0;
memset(a, 0, sizeof(a));
jloop(0, N) if (det[j] != -1) {a[j] = det[j];}
//cout << "Test: ";
//jloop(0, N) cout << a[j] << " ";
//cout << "\n";
if (tryCombination(a) == i) main = 1;
jloop(0, N) if (det[j] == -1) a[j] = main;
if (i == N-1) {
jloop(0, N) if (det[j] == -1) {ans[j] = main, ans2[j] = i;}
break;
}
vector<ll> val;
jloop(0, N) if (det[j] == -1) val.push_back(j);
ll lb = 0, ub = N-i-1, mid;
while (lb < ub) {
mid = (lb + ub)>>1;
jloop(mid+1, ub+1) a[val[j]] = main^1;
//cout << "Test: ";
//jloop(0, N) cout << a[j] << " ";
//cout << "\n";
ll tmp = tryCombination(a);
//cout << tmp << "res\n";
if (tmp > i || tmp == -1) {
ub = mid;
}
else {
jloop(mid+1, ub+1) a[val[j]] = main;
lb = mid + 1;
}
}
det[val[lb]] = main;
ans[val[lb]] = main;
ans2[val[lb]] = i;
//cout << lb << " " << val[lb] << "g\n";
}
answer(ans, ans2);
}
| # | 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... |