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>
#define Nmax 1005
#include "library.h"
using namespace std;
#define f first
#define s second
typedef pair<int, int> pii;
int n, used[Nmax], conta = 0, ans[Nmax], ans2[Nmax];
int esq[Nmax], dir[Nmax];
int lower_bound(int x)
{
int ini = 1, fim = x - 1, mid, best = -1;
while(fim >= ini)
{
mid = (ini + fim)/2;
vector<int> v (n);
for(int i = 1; i <= mid; i++) v[i - 1] = 1;
v[x - 1] = 1;
int q = ans[mid] - Query(v);
if(q == 0) best = mid, fim = mid - 1;
else if(q < 0) ini = mid + 1;
else fim = mid - 1;
}
return best;
}
int upper_bound(int x)
{
int ini = 1, fim = x - 1, mid, best = -1;
while(fim >= ini)
{
mid = (ini + fim)/2;
vector<int> v (n);
for(int i = 1; i <= mid; i++) v[i - 1] = 1;
v[x - 1] = 1;
int q = ans[mid] - Query(v);
if(q == 1) best = mid, fim = mid - 1;
else if(q < 1) ini = mid + 1;
else fim = mid - 1;
}
return best;
}
set<int> viz[Nmax];
void Solve(int N_)
{
n = N_;
if(n == 1)
{
vector<int> A(1);
A[0] = 1;
Answer(A);
return;
}
ans[1] = 1, esq[1] = dir[1] = -1;
for(int i = 2; i <= n; i++)
{
esq[i] = lower_bound(i);
dir[i] = upper_bound(i);
vector<int> v (n);
for(int j = 1; j <= i; j++) v[j - 1] = 1;
ans[i] = Query(v);
}
vector<int> resp;
for(int i = 1; i <= n; i++)
{
if(esq[i] != -1) viz[i].insert(esq[i]);
if(dir[i] != -1) viz[i].insert(dir[i]);
if(esq[i] != -1) viz[ esq[i] ].insert(i);
if(dir[i] != -1) viz[ dir[i] ].insert(i);
}
for(int i = 1; i <= n; i++)
{
vector<int> v (n);
for(int j = 1; j <= n; j++) v[j - 1] = 1;
v[i - 1] = 0;
if(Query(v) == 1)
{
used[i] = 1;
resp.push_back(i);
break;
}
}
while(true)
{
int x = resp.back(), cnt = 0;
for(auto v: viz[x])
{
if(used[v]) continue;
used[v] = 1;
resp.push_back(v), cnt ++;
break;
}
if(!cnt) break;
}
Answer(resp);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |