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 "cave.h"
using namespace std;
/*
int tryCombination(int S[]) {
for(int i = 0; i < 4; i++) {
cout << S[i] << " ";
}
cout << endl;
int x;
cin >> x;
return x;
}
void answer(int c[], int d[]) {
}*/
void exploreCave(int N) {
int c[N];
int D[N];
int S[N];
int izracunao[N];
for(int i = 0; i < N; i += 1) {
S[i] = 0;
izracunao[i] = 0;
}
for(int i = 1; i <= N; i++) {
int ask = tryCombination(S);
if(ask == - 1) {
ask = N + 1;
}
if(ask >= i) {
// 0 je
int l = 0, r = N - 1, p = - 1;
while(l <= r) {
int mid = (l + r) / 2;
for(int j = mid; j < N; j += 1) {
if(izracunao[j]) {
continue;
}
S[j] ^= 1;
}
int ask = tryCombination(S);
if(ask == - 1) {
ask = N + 1;
}
if(ask >= i) {
l = mid + 1;
p = mid;
}
else {
r = mid - 1;
}
for(int j = mid; j < N; j += 1) {
if(izracunao[j]) {
continue;
}
S[j] ^= 1;
}
}
izracunao[p] = 1;
D[p] = i - 1;
//cout << "! " << p << " " << i - 1;
//cout << endl;
}
else {
// 1 je
int l = 0, r = N - 1, p = - 1;
while(l <= r) {
int mid = (l + r) / 2;
for(int j = 0; j <= mid; j += 1) {
if(izracunao[j]) {
continue;
}
S[j] ^= 1;
}
int ask = tryCombination(S);
if(ask == - 1) {
ask = N + 1;
}
if(ask >= i) {
r = mid - 1;
p = mid;
}
else {
l = mid + 1;
}
for(int j = 0; j <= mid; j += 1) {
if(izracunao[j]) {
continue;
}
S[j] ^= 1;
}
}
//cout << "! " << p << " " << i - 1;
//cout << endl;
izracunao[p] = 1;
S[p] = 1;
D[p] = i - 1;
}
}
answer(S, D);
//cout << endl;
for(int i = 0; i < N; i++) {
//cout << S[i] << " ";
}
//cout << endl;
for(int i = 0; i < N; i += 1) {
//cout << D[i] << " ";
}
}
/*
int main() {
exploreCave(4);
}*/
Compilation message (stderr)
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:22:9: warning: unused variable 'c' [-Wunused-variable]
22 | int c[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... |