| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 776796 | Sandarach151 | Cave (IOI13_cave) | C++17 | 0 ms | 0 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>
using namespace std;
int sze;
int try_combination(int arr[]){
    for(int i=0; i<sze; i++){
        cout << arr[i] << ' ';
    }
    cout << '\n';
    int ans;
    cin >> ans;
    return ans;
}
void answer(int arr[], int arr2[]){
    cout << "------------------------ANSWER-----------------------\n";
    for(int i=0; i<sze; i++){
        cout << arr[i] << ' ' << arr2[i] << '\n';
    }
}
void exploreCave(int n) {
    pair<int, int> curans[n] = {{-1, -1}}; // for each door, what is switch number and position
    for(int i=0; i<n; i++){
        int arr[n];
        for(int j=0; j<n; j++){
            arr[j]=-1;
        }
        vector<int> rest;
        int spos;
        for(int j=0; j<i; j++){
            arr[curans[j].first]=curans[j].second;
        }
        for(int j=0; j<n; j++){
            if(arr[j]==-1){
                arr[j]=0;
                rest.push_back(j);
            }
        }
        try_combination(arr)>i ? spos = 0 : spos = 1;
        if(spos==0){
            int lb = 0;
            int ub = rest.size()-1;
            while(lb!=ub){
                int mid = (lb+ub)/2;
                for(int j=lb; j<=mid; j++){
                    arr[rest[j]]=0;
                }
                for(int j=mid+1; j<=ub; j++){
                    arr[rest[j]]=1;
                }
                int temp = try_combination(arr);
                temp>i || temp==-1 ? ub = mid : lb = mid+1;
            }
            curans[i]={rest[lb], spos};
        }
        else{
            int lb = 0;
            int ub = rest.size()-1;
            while(lb!=ub){
                int mid = (lb+ub)/2;
                for(int j=lb; j<=mid; j++){
                    arr[rest[j]]=1;
                }
                for(int j=mid+1; j<=ub; j++){
                    arr[rest[j]]=0;
                }
                int temp = try_combination(arr);
                temp>i || temp==-1 ? ub = mid : lb = mid+1;
            }
            curans[i]={rest[lb], spos};
        }
    }
    int ans1[n];
    int ans2[n];
    for(int i=0; i<n; i++){
        ans1[curans[i].first] = i;
        ans2[curans[i].first] = curans[i].second;
    }
    answer(ans1, ans2);    
}
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        sze = n;
        exploreCave(n);
    }
    return 0;
}
