# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1080158 | adaawf | Library (JOI18_library) | C++17 | 30 ms | 344 KiB |
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 <iostream>
#include <vector>
#include <assert.h>
#include "library.h"
using namespace std;
int dd[1005];
/*int Query(vector<int> v) {
for (int w : v) cout << w << " ";
cout << endl;
int x;
cin >> x;
return x;
}
void Answer(vector<int> v) {
for (int w : v) cout << w << " ";
cout << endl;
}*/
void Solve(int n) {
for (int i = 0; i < n; i++) dd[i] = 0;
vector<int> res;
for (int i = 0; i < n; i++) {
vector<int> vv;
for (int j = 0; j < n; j++) {
if (i == j) vv.push_back(0);
else vv.push_back(1);
}
if (Query(vv) == 1) {
res.push_back(i);
break;
}
}
for (int i = 0; i < n; i++) {
if (i == res.back()) continue;
vector<int> vv;
for (int j = 0; j < n; j++) {
if (j == i || j == res.back()) vv.push_back(1);
else vv.push_back(0);
}
if (Query(vv) == 1) {
res.push_back(i);
break;
}
}
assert(res.size() == 2);
dd[res[0]] = dd[res[1]] = 1;
for (int i = 2; i < n; i++) {
vector<int> v;
for (int j = 0; j < n; j++) {
if (dd[j] == 0) {
v.push_back(j);
}
}
int l = 0, r = v.size() - 2, g = v.size() - 1;
while (l <= r) {
int mid = (l + r) / 2;
vector<int> vv(n, 0);
for (int j = 0; j <= mid; j++) vv[v[j]] = 1;
for (int j = 0; j < res.size(); j++) vv[res[j]] = 1;
int h = Query(vv);
vv[res.back()] = 0;
int k = Query(vv);
if (h != k) {
g = mid;
r = mid - 1;
}
else l = mid + 1;
}
res.push_back(v[g]);
dd[v[g]] = 1;
}
for (int &w : res) w++;
Answer(res);
}
/*int main() {
Solve(5);
}*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |