# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47838 | Inovak | Library (JOI18_library) | C++14 | 554 ms | 580 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 "library.h"
//#include "grader.cpp"
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define ll long long
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
using namespace std;
bool u[3000];
void Solve(int n)
{
vector<int> M(n);
deque <int> dq;
dq.pb(1);
u[0] = 1;
M[0] = 1;
int ans = -1, anb = -1;
for(int i = 0; i < n; i++) {
if(u[i]) continue;
M[i] = 1;
int A = Query(M);
if(A == 1 && ans == -1) ans = i;
else if(A == 1) anb = i;
M[i] = 0;
}
M[0] = 0;
if(n > 1) {
u[ans] = 1;
dq.pb(ans + 1);
}
while(dq.size() < n) {
M[ans] = 1;
int an = -1;
for(int i = 0; i < n; i++) {
if(u[i]) continue;
M[i] = 1;
int A = Query(M);
M[i] = 0;
if(A == 1) an = i;
}
M[ans] = 0;
if(an == -1) break;
u[an] = 1;
ans = an;
dq.pb(ans + 1);
}
if(dq.size() < n) {
ans = anb;
u[ans] = 1;
dq.push_front(ans + 1);
while(dq.size() < n) {
M[ans] = 1;
int an = -1;
for(int i = 0; i < n; i++) {
if(u[i]) continue;
M[i] = 1;
int A = Query(M);
M[i] = 0;
if(A == 1) an = i;
}
M[ans] = 0;
if(an == -1) break;
u[an] = 1;
ans = an;
dq.push_front(ans + 1);
}
}
vector <int> res;
while(!dq.empty())
res.pb(dq.front()), dq.pop_front();
Answer(res);
}
/**
5
4 2 5 3 1
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |