# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963689 | yellowtoad | Library (JOI18_library) | C++17 | 198 ms | 696 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 <cstdio>
#include <vector>
#include <iostream>
#include "library.h"
using namespace std;
void Solve(int n)
{
int x, y;
vector<int> b(n,1), res, tmp, tmmp;
if (n == 1) {
Answer({1});
return;
}
for (int i = 1; i <= n; i++) {
b[i-1] = 0;
if (Query(b) == 1) {
res.push_back(i);
for (int j = 1; j <= n; j++) if (j != i) tmp.push_back(j);
break;
}
b[i-1] = 1;
}
for (int i = 2; i <= n; i++) {
int l = 0, r = tmp.size()-1;
while (l != r) {
int mid = (l+r)/2;
for (int j = 0; j < n; j++) b[j] = 0;
for (int j = 0; j < res.size(); j++) b[res[j]-1] = 1;
for (int j = 0; j <= mid; j++) b[tmp[j]-1] = 1;
x = Query(b);
b[res.back()-1] = 0;
y = Query(b);
if (i == 2) {
if (x == y) r = mid;
else l = mid+1;
} else {
if (y > x) r = mid;
else l = mid+1;
}
}
res.push_back(tmp[l]);
tmmp.clear();
for (int j = 0; j < tmp.size(); j++) if (j != l) tmmp.push_back(tmp[j]);
tmp = tmmp;
}
Answer(res);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |