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 "cave.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
int l,r;
vector<int> v;
vector<int> :: iterator it;
void exploreCave(int N) {
int x[N];
int a[N];
int tp[N];
int ans[N];
memset(a, 0, sizeof(a));
//
for(int i = 0; i < N; i ++) {
v.pb(i);
}
//
int ok = 0;
int tur = tryCombination(a);
if(tur >= 1) ok = 1;
memset(tp, -1, sizeof(tp));
//
for(int i = 0; i < N; i ++) { // we are looking for i-th door
l = 0;
r = v.size() - 1;
int tmp;
while(l < r) {
int mid = (l + r) / 2;
// cout << l << ' ' << r << ' ' << mid << '\n';
// cout << "OK: " << ok << '\n';
for(int j = l; j <= mid; j ++) {
a[v[j]] = 1 - a[v[j]];
}
tmp = tryCombination(a);
// for(int j = 0; j < N; j ++) {
// cout << a[j] << ' ';
// }
// cout << '\n';
if(tmp == -1) tmp = N;
//cout << "TMP: " << tmp << '\n';
if(tmp > i && ok == 0) {
r = mid;
ok = 1;
}
else if(tmp > i && ok == 1) {
l = mid + 1;
ok = 1;
}
else if(ok == 1) {
r = mid;
ok = 0;
}
else {
l = mid + 1;
ok = 0;
}
//
if(l == r) {
// cout << "POS: " << v[l] << '\n';
// cout << "WTF " << ok << '\n';
if(ok == 0) {
a[v[l]] = 1 - a[v[l]];
}
tp[v[l]] = a[v[l]];
tmp = tryCombination(a);
if(tmp == -1) tmp = N;
if(tmp > i + 1) ok = 1;
else ok = 0;
}
}
ans[v[l]] = i;
if(tp[v[l]] == -1) {
if(ok == 0) tp[v[l]] = 1 - a[v[l]];
else tp[v[l]] = a[v[l]];
}
it = lower_bound(v.begin(), v.end(), v[l]);
v.erase(it);
// cout << "IN the V: ";
// for(int j = 0; j < v.size(); j ++) {
// cout << v[j] << ' ';
// }
// cout << '\n';
// cout << "OK: " << ok << '\n';
// for(int j = 0; j < N; j ++) {
// cout << a[j] << ' ';
// }
// cout << "\n\n";
}
answer(tp, ans);
}
Compilation message (stderr)
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:17:9: warning: unused variable 'x' [-Wunused-variable]
17 | int x[N];
| ^
# | 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... |