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"
using namespace std;
using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;
#define sz(v) ((int)v.size())
#define pb push_back
#define pry cout << "YES\n"
#define prn cout << "NO\n"
#define endl '\n'
#define fst first
#define scn second
/* #define ONPC */
const int N = 1e3;
bitset<N+5> c;
vector<int> m;
int n;
int Query(const vector<int> &M);
void Answer(const vector<int> &res);
bool
comp(int l, int r, int x)
{
for (int i = 0; i < n; ++i) {
m[i] = 0;
}
int cnt = 0;
for (int i = 1; i < n+1; ++i) {
if (c[i])
continue;
if (cnt >= l && cnt < r)
m[i-1] = 1;
++cnt;
}
int a1 = Query(m);
m[x-1] = 1;
int a2 = Query(m);
return (a1 == a2);
}
int
arrsize()
{
int s = 0;
for (int i = 1; i < n+1; ++i) {
if (!c[i])
++s;
}
return s;
}
int
getval(int l)
{
for (int i = 1; i < n+1; ++i) {
if (c[i])
continue;
--l;
if (!l)
return i;
}
return -1;
}
int
bs(int x)
{
int l = 0;
int r = arrsize();
if (r == 1)
return getval(1);
if (r == 0)
return 0;
int mid;
while (l < r-1) {
mid = (l+r)>>1;
if (comp(l,mid,x))
r = mid;
else
l = mid;
}
return getval(l+1);
}
void
Solve(int _n)
{
n = _n;
assert(n != 1);
m.assign(n,1);
int val = -1;
for (int i = 1; i < n+1; ++i) {
m[i-1] = 0;
if (Query(m) == 1) {
val = i;
break;
}
m[i-1] = 1;
}
c[val] = 1;
vector<int> ans;
ans.pb(val);
int cnt = 1;
while (1) {
val = bs(val);
assert(val != -1);
if (!val)
break;
c[val] = 1;
ans.pb(val);
++ cnt;
}
Answer(ans);
return;
}
#ifdef ONPC
vector<int> p;
int rn;
int
Query(const vector<int> &M)
{
int ans = 0;
if (M[p[0]-1])
++ans;
for (int i = 1; i < rn; ++i) {
if(M[p[i-1]-1] == 0 && M[p[i]-1] == 1)
++ans;
}
assert(ans != 0);
return ans;
}
void
Answer(const vector<int> &res)
{
for (int i = 0; i < rn; ++i) {
cout << res[i] << ' ';
}
cout << endl;
}
void
solve()
{
cin >> rn;
p.resize(rn);
cout << rn << endl;
for (int i = 0; i < rn; ++i) {
cin >> p[i];
}
Solve(rn);
}
int32_t
main(int argc, char **argv)
{
if (argc >= 2) {
freopen(argv[1], "r", stdin);
} else
ios_base::sync_with_stdio(0);cin.tie(0);
int t = 1;
/* cin >> t; */
while(t--)
solve();
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |