# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
766934 | ParsaS | Library (JOI18_library) | C++17 | 265 ms | 336 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<bits/stdc++.h>
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;
const int N = 1000 + 5;
void Solve(int n)
{
vector<int> res(n);
if (n == 1) {
res[0] = 1;
Answer(res);
return;
}
for (int i = 0; i < n; i++) {
vector<int> M(n, 1);
assert(M[0]);
M[i] = 0;
int x = Query(M);
if (x == 1)
res[0] = i;
}
vector<int> A(n, 1);
A[res[0]] = 0;
for (int i = 1; i < n; i++) {
vector<int> B(n);
int cnt = 0;
for (int j = 0; j < n; j++)
B[j] = A[j], cnt += B[j];
while (cnt > 1) {
int c = 0;
vector<int> M(n, 0);
for (int j = 0; j < n; j++) {
if (c < cnt / 2 && B[j])
M[j] = 1, c++;
}
int x = Query(M);
M[res[i - 1]] = 1;
int y = Query(M);
int k = 0;
vector<int> C(n);
if (x == y) {
c = 0;
for (int j = 0; j < n; j++) {
if (c < cnt / 2 && B[j])
C[j] = 1, k++;
c += B[j];
}
}
else {
c = 0;
for (int j = 0; j < n; j++) {
if (c >= cnt / 2 && B[j])
C[j] = 1, k++;
c += B[j];
}
}
B = C;
cnt = k;
}
for (int j = 0; j < n; j++)
if (B[j])
res[i] = j, A[j] = 0;
}
for (int j = 0; j < n; j++)
++res[j];
Answer(res);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |