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 forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
/*
int tryCombination(vector<int> s) {
for(auto x: s) cout << x << " ";
cout << "\n";
int f; cin >> f;
return f;
}
void answer(vector<int> s, vector<int> d) {
for(auto x: s) cout << x << " ";
cout << "\n";
for(auto x: d) cout << x << " ";
cout << "\n";
}
*/
void exploreCave(int n) {
int d[n], s[n];
forn(i, n) d[i] = s[i] = -1;
for(int i = 0; i < n; ++i) {
int tmp[n];
forn(j, n) tmp[j] = s[j];
forn(j, n) if(s[j] == -1) tmp[j] = 0;
int x = tryCombination(tmp);
int need = 0;
if(x == -1) x = n;
if(x <= i) {
need = 1;
forn(j, n) if(s[j] == -1) tmp[j] = 1;
}
d[i] = need;
int l = 0, r = n - 1, pos = -1;
while(l <= r) {
int rem[n];
forn(j, n) rem[j] = tmp[j];
int mid = l + r >> 1;
for(int j = mid; j < n; ++j) {
if(s[j] == -1) {
tmp[j] = !need;
}
}
x = tryCombination(tmp);
if(x == -1) x = n;
if(x <= i) {
r = mid - 1;
} else {
pos = mid;
l = mid + 1;
}
forn(j, n) tmp[j] = rem[j];
}
s[pos] = i;
}
answer(d, s);
}
/*
void solve() {
int n; cin >> n;
exploreCave(n);
}
int32_t main() {
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
*/
Compilation message (stderr)
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:50:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | int mid = l + r >> 1;
| ~~^~~
# | 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... |