#include<bits/stdc++.h>
#include "library.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
/*namespace {
struct Judge
{
int N;
int A[1002];
int pos[1002];
bool f[1002];
int query_c;
bool answered;
void init()
{
query_c=0;
int ret=scanf("%d",&N); ret++;
answered=false;
for(int i=0;i<N;i++)ret=scanf("%d",&A[i]),pos[A[i]]=i;
}
int query(const vector<int>& M)
{
if(query_c==20000)
{
puts("Wrong Answer [3]");
exit(0);
}
if(int(M.size())!=N)
{
puts("Wrong Answer [1]");
exit(0);
}
bool all_zero=true;
for(int i=0;i<N;i++)
{
if(M[i]!=0&&M[i]!=1)
{
puts("Wrong Answer [2]");
exit(0);
}
if(M[i]==1)all_zero=false;
}
if(all_zero)
{
puts("Wrong Answer [2]");
exit(0);
}
memset(f,0,sizeof(f));
for(int i=0;i<N;i++)if(M[i])f[pos[i+1]]=true;
bool las=false;
int r=0;
for(int i=0;i<N;i++)
{
if(las==false&&f[i]==true)r++;
if (f[i]){
//cerr<<i+1<<'\n';
}
las=f[i];
}
query_c++;
return r;
}
void answer(const vector<int>& res)
{
bool f1=true,f2=true;
if(int(res.size())!=N)
{
puts("Wrong Answer [4]");
exit(0);
}
if(answered)
{
puts("Wrong Answer [7]");
exit(0);
}
answered=true;
memset(f,0,sizeof(f));
for(int i=0;i<N;i++)
{
if(res[i]<=0||res[i]>N)
{
puts("Wrong Answer [5]");
exit(0);
}
if(f[res[i]])
{
puts("Wrong Answer [6]");
exit(0);
}
f[res[i]]=true;
}
for(int i=0;i<N;i++)
{
f1&=A[i]==res[i];
f2&=A[i]==res[N-i-1];
}
if(!f1&&!f2)
{
puts("Wrong Answer [8]");
exit(0);
}
}
void end()
{
if(!answered)puts("Wrong Answer [7]");
else printf("Accepted : %d\n",query_c);
}
}judge;
}
int Query(const vector<int>& M)
{
return judge.query(M);
}
void Answer(const vector<int>& res)
{
judge.answer(res);
}*/
bool use[1009];
void Solve(int n){
vector<vector<int>>gr;
gr.pb({1});
for1(i,2,n){
vector<int>t;
for1(j,1,i)t.pb(j);
vector<int>t1;
for1(j,1,n)use[j]=0;
for (auto v:t){
use[v]=1;
}
for1(j,1,n){
t1.pb(use[j]);
}
int nans=Query(t1);
//cout<<i<<" "<<nans<<'\n';
if (nans==sz(gr)+1){
gr.pb({i});
continue;
}
else if (nans==sz(gr)){
int l=0,r=sz(gr)-1,ans=r;
//cerr<<l<<" "<<r<<'\n';
while (l<=r){
int mid=(l+r)/2;
vector<int>tt;
for1(j,0,mid){
for(auto v:gr[j]){
tt.pb(v);
}
}
//cerr<<mid<<'\n';
tt.pb(i);
for1(j,1,n)use[j]=0;
for (auto v:tt){
use[v]=1;
}
vector<int>tt1;
for1(j,1,n)tt1.pb(use[j]);
int val=Query(tt1);
if (val==mid+1){
ans=mid;
r=mid-1;
}
else l=mid+1;
}
if (sz(gr[ans])==1){
gr[ans].pb(i);
}
else {
vector<int>newask;
for1(j,1,n)use[j]=0;
use[i]=1;
use[gr[ans].back()]=1;
for1(j,1,n)newask.pb(use[j]);
int n1=Query(newask);
if (n1==2){
reverse(all(gr[ans]));
gr[ans].pb(i);
}
else {
gr[ans].pb(i);
}
}
//cerr<<ans<<'\n';
continue;
}
else{
int l=0,r=sz(gr)-1,ans=r;
while (l<=r){
int mid=(l+r)/2;
vector<int>tt;
for1(j,0,mid){
for(auto v:gr[j]){
tt.pb(v);
}
}
tt.pb(i);
vector<int>tt1;
for1(j,1,n)use[j]=0;
for (auto v:tt){
use[v]=1;
}
for1(j,1,n)tt1.pb(use[j]);
int val=Query(tt1);
if (val<=mid+1){
ans=mid;
r=mid-1;
}
else l=mid+1;
}
//cerr<<ans<<'\n';
l=ans+1,r=sz(gr)-1;
int ano=r;
while (l<=r){
int mid=(l+r)/2;
vector<int>tt;
for1(j,0,mid){
if (j==ans)continue;
for(auto v:gr[j]){
tt.pb(v);
}
}
tt.pb(i);
vector<int>tt1;
for1(j,1,n)use[j]=0;
for(auto v:tt){
use[v]=1;
}
for1(j,1,n){
tt1.pb(use[j]);
}
int val=Query(tt1);
if (val<=mid){
ano=mid;
r=mid-1;
}
else l=mid+1;
}
vector<vector<int>>newgr;
for1(j,0,sz(gr)-1){
if (j==ano||j==ans){
continue;
}
else {
//if (j==ans)ans=sz(newgr);
newgr.pb(gr[j]);
}
}
vector<int>newask;
for1(j,1,n){
if (j==gr[ans].back()||j==i){
newask.pb(1);
}
else newask.pb(0);
}
int lol=Query(newask);
if (lol==1){
gr[ans].pb(i);
vector<int>a1;
for1(j,1,n){
if (j==i||j==gr[ano].back()){
a1.pb(1);
}
else a1.pb(0);
}
int checkrev=Query(a1);
if (checkrev==1){
reverse(all(gr[ano]));
}
for (auto u:gr[ano]){
gr[ans].pb(u);
}
newgr.pb(gr[ans]);
}
else {
reverse(all(gr[ans]));
gr[ans].pb(i);
vector<int>a1;
for1(j,1,n){
if (j==i||j==gr[ano].back()){
a1.pb(1);
}
else a1.pb(0);
}
int checkrev=Query(a1);
if (checkrev==1){
reverse(all(gr[ano]));
}
for (auto u:gr[ano]){
gr[ans].pb(u);
}
newgr.pb(gr[ans]);
}
gr.swap(newgr);
continue;
}
}
/*cout<<sz(gr)<<'\n';
for (auto v:gr){
for(auto u:v){
cout<<u<<" ";
}
cout<<'\n';
}*/
Answer(gr[0]);
}
/*signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen(".OUT","w",stdout);
judge.init();
Solve(judge.N);
judge.end();
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
208 KB |
# of queries: 1263 |
2 |
Correct |
16 ms |
308 KB |
# of queries: 1242 |
3 |
Correct |
14 ms |
208 KB |
# of queries: 1306 |
4 |
Correct |
19 ms |
292 KB |
# of queries: 1304 |
5 |
Correct |
20 ms |
208 KB |
# of queries: 1305 |
6 |
Correct |
16 ms |
312 KB |
# of queries: 1284 |
7 |
Correct |
17 ms |
208 KB |
# of queries: 1290 |
8 |
Correct |
17 ms |
208 KB |
# of queries: 1231 |
9 |
Correct |
16 ms |
304 KB |
# of queries: 1312 |
10 |
Correct |
9 ms |
316 KB |
# of queries: 766 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 9 |
15 |
Correct |
1 ms |
208 KB |
# of queries: 51 |
16 |
Correct |
2 ms |
208 KB |
# of queries: 112 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
208 KB |
# of queries: 1263 |
2 |
Correct |
16 ms |
308 KB |
# of queries: 1242 |
3 |
Correct |
14 ms |
208 KB |
# of queries: 1306 |
4 |
Correct |
19 ms |
292 KB |
# of queries: 1304 |
5 |
Correct |
20 ms |
208 KB |
# of queries: 1305 |
6 |
Correct |
16 ms |
312 KB |
# of queries: 1284 |
7 |
Correct |
17 ms |
208 KB |
# of queries: 1290 |
8 |
Correct |
17 ms |
208 KB |
# of queries: 1231 |
9 |
Correct |
16 ms |
304 KB |
# of queries: 1312 |
10 |
Correct |
9 ms |
316 KB |
# of queries: 766 |
11 |
Correct |
0 ms |
208 KB |
# of queries: 0 |
12 |
Correct |
0 ms |
208 KB |
# of queries: 2 |
13 |
Correct |
0 ms |
208 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
208 KB |
# of queries: 9 |
15 |
Correct |
1 ms |
208 KB |
# of queries: 51 |
16 |
Correct |
2 ms |
208 KB |
# of queries: 112 |
17 |
Correct |
213 ms |
340 KB |
# of queries: 8718 |
18 |
Correct |
156 ms |
348 KB |
# of queries: 8671 |
19 |
Correct |
169 ms |
332 KB |
# of queries: 8706 |
20 |
Correct |
174 ms |
340 KB |
# of queries: 8127 |
21 |
Correct |
158 ms |
340 KB |
# of queries: 7650 |
22 |
Correct |
175 ms |
356 KB |
# of queries: 8773 |
23 |
Correct |
195 ms |
364 KB |
# of queries: 8695 |
24 |
Correct |
62 ms |
316 KB |
# of queries: 3999 |
25 |
Correct |
163 ms |
444 KB |
# of queries: 8537 |
26 |
Correct |
167 ms |
340 KB |
# of queries: 7973 |
27 |
Correct |
63 ms |
320 KB |
# of queries: 4003 |
28 |
Correct |
63 ms |
320 KB |
# of queries: 2996 |
29 |
Correct |
65 ms |
316 KB |
# of queries: 2993 |
30 |
Correct |
73 ms |
340 KB |
# of queries: 2996 |