이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
int calls = 0;
int ask(int comb[]){
calls++;
assert(calls <= 70000);
return tryCombination(comb);
}
void exploreCave(int N) {
int comb[N], S[N], D[N];
fill(S, S + N, -1);
vector<int> free;
for (int i = 0; i < N; i++) free.push_back(i);
for (int i = 0; i < N; i++){
int ind = 0;
for (int j = 0; j < N; j++){
comb[j] = (S[j] != -1 ? S[j] : 0);
}
int last = ask(comb);
int x = (last == i && last != -1);
int l = 0, r = free.size() - 1;
while (l <= r){
int mid = (l + r) >> 1;
for (int j = 0; j < N; j++){
comb[j] = (S[j] != -1 ? S[j] : (x ^ 1));
}
comb[free[mid]] = x;
if (ask(comb) != i){
ind = mid;
r = mid - 1;
} else l = mid + 1;
}
int pos = free[ind];
S[pos] = x;
D[pos] = i;
//cout << x << ' ' << pos << endl;
free.erase(free.begin() + ind, free.begin() + ind + 1);
}
answer(S, D);
}
/*
4
1 1 1 0
3 1 0 2
5
0 1 0 1 0
2 4 0 1 3
*/
| # | 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... |