# JOI 2011 春合宿 Guess Them All ( Binary Search, Interaction )

guess: 数当て (Guess Them All) - 2011年 日本情報オリンピック春合宿OJ | AtCoder

input:
1

```#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 2;
const int MAXL = 700;

int n, pos[ MAXN ], num[ MAXN ];
vector<int> unknown;

int qry[ MAXN ];

for(int i = 1; i <= n; ++i)
printf("%d\n", qry[ i ]);
fflush( stdout );
int ret; scanf("%d", &ret);
return ret;
}

void solve(){
if( n == 1 ){
qry[ 1 ] = 1;
return;
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if( j == i ) puts("1");
else puts("2");
}
fflush( stdout );
int v; scanf("%d", &v);
if( v == 2 ){
pos[ 1 ] = i;
num[ i ] = 1;
break;
}
}
for(int i = 1; i <= n; ++i){
if( num[ i ] == 1 ) continue;
unknown.push_back( i ); // which positions in answer array are remained unknown
}
for(int i = 2; i <= n; ++i){
int lb = 0, rb = unknown.size();
while( lb + 1 < rb ){
int mid = ( lb + rb ) / 2;

memset( qry, 0, sizeof(qry) );
for(int j = lb; j < mid; ++j)
qry[ unknown[ j ] ] = i;
int one_is_counted = 0;
for(int j = 1; j <= n; ++j)
if( qry[ j ] == 0 ){
qry[ j ] = 1;
if( num[ j ] == 1 ) one_is_counted = 1;
}

bool is_left;
if( ask() == 1 + one_is_counted ) is_left = true;
else is_left = false;

if( is_left ) rb = mid;
else lb = mid;
}
pos[ i ] = unknown[ lb ];
num[ unknown[ lb ] ] = i;
// while( lb < 0 || lb >= unknown.size() );
// while( unknown[ lb ] < 1 || unknown[ lb ] > n );
// while( num[ unknown[ lb ] ] == 0 );
unknown.erase( unknown.begin() + lb );
}
// while( unknown.size() == 1 );
for(int i = 1; i <= n; ++i){
printf("%d\n", num[ i ]);
// while( num[ i ] == 0 );
}
fflush( stdout );
int ret; scanf("%d", &ret);
while( ret != n );
}

int main(){
scanf("%d", &n);
solve();
return 0;
}
```