#ifndef LOCAL
#include "cave.h"
#endif
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
using ll = long long;
const int N = 5000 + 24;
#ifdef LOCAL
int n, real_s[N], real_d[N];
int tryCombination(int S[]) {
for (int i = 0; i < n; i++) {
cout << S[i] << ' ';
}
cout << endl;
vector<int> state(n);
for (int i = 0; i < n; i++) {
int j = real_d[i];
state[j] = (S[i] == real_s[i]);
}
cout << "STATE: ";
for (int j = 0; j < n; j++) cout << state[j] << ' '; cout << endl;
for (int i = 0; i < n; i++) {
if (!state[i]) return cout << i << endl, i;
}
return cout << -1 << endl, -1;
}
void answer(int S[], int D[]) {
bool valid = 1;
for (int i = 0; i < n; i++) {
if (S[i] != real_s[i]) {
valid = 0;
break;
}
}
for (int i = 0; i < n; i++) {
if (D[i] != real_d[i]) {
valid = 0;
break;
}
}
if (!valid) {
cout << "WRONG ANSWER" << endl;
for (int i = 0; i < n; i++) cout << S[i] << ' '; cout << endl;
for (int i = 0; i < n; i++) cout << D[i] << ' '; cout << endl;
}
else {
cout << "CORRECT" << endl;
}
}
#endif
void exploreCave(int N) {
int n = N;
int state[n], new_state[n];
int can[n];
for (int i = 0; i < n; i++) {
state[i] = new_state[i] = 0;
can[i] = 1;
}
for (int i = 0; i < n; i++) {
int k = tryCombination(state);
int m = tryCombination(can);
if (k == -1) break;
if (m != -1 && m < k) {
int pos = -1;
for (int l = 0, r = n - 1; l <= r; ) {
int mid = (l + r) >> 1;
for (int i = 0; i < n; i++) {
new_state[i] = state[i];
}
for (int i = 0; i <= mid; i++) {
if (can[i]) new_state[i] = 1;
}
int jury_ans = tryCombination(new_state);
if (jury_ans != -1 && jury_ans < k) {
pos = mid;
r = mid - 1;
}
else l = mid + 1;
}
if (pos != -1) {
can[pos] = 0;
cout << "POS = " << pos << "\n";
}
}
else {
int pos = -1;
for (int l = 0, r = n - 1; l <= r; ) {
int mid = (l + r) >> 1;
for (int i = 0; i < n; i++) {
new_state[i] = state[i];
}
for (int i = 0; i <= mid; i++) {
if (can[i]) new_state[i] = 1;
}
int jury_ans = tryCombination(new_state);
if (jury_ans == -1 || jury_ans > k) {
pos = mid;
r = mid - 1;
}
else l = mid + 1;
}
if (pos != -1) {
cout << "POS = " << pos << "\n";
state[pos] = 1;
}
}
}
int d[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
new_state[j] = state[j];
}
new_state[i] ^= 1;
d[i] = tryCombination(new_state);
}
return answer(state, d);
}
#ifdef LOCAL
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> real_s[i];
}
for (int i = 0; i < n; i++) {
cin >> real_d[i];
}
exploreCave(n);
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int T = 1; // cin >> T;
while (T--) {
solve();
}
}
#endif
| # | 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... |