結果

問題 No.1959 Prefix MinMax
ユーザー momoyuu
提出日時 2023-07-16 01:17:55
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 250,956 KB
実行使用メモリ 25,580 KB
平均クエリ数 39.69
最終ジャッジ日時 2024-09-17 09:35:34
合計ジャッジ時間 5,691 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> p(n,-1);
        cout<<"?";
        string now = "";
        for(int i = 0;i<n-1;i++){
            cout<<" ";
            if(i%2==0) {
                cout<<1;
                now += "1";
            }
            else {
                cout<<0;
                now += "0";
            }
        }
        cout<<endl;
        vector<int> s(n);
        for(int i = 0;i<n;i++) cin>>s[i];
       
        int q = 10;
        while(q--){
            p[0] = s[0];
            for(int i = 1;i<n;i++){
                if(s[i-1]!=s[i]) p[i] = s[i];
            }
            bool ok = true;
            for(int i = 0;i<n;i++){
                if(p[i] == -1) ok = false;
            }
            if(ok) break;
            if(q==0) break;
            cout<<"?";
            string nxt = "";
            for(int i = 0;i<n-1;i++){
                cout<<" ";
                if(p[i+1]!=-1){
                    cout<<now[i];
                    nxt += now[i];
                }else{
                    if(now[i]=='1'){
                        cout<<0;
                        nxt += "0";
                    }else{
                        cout<<1;
                        nxt += "1";
                    }
                }
            }
            cout<<endl;
            for(int i = 0;i<n;i++) cin>>s[i];
            swap(now,nxt);
        }
        cout<<"!";
        for(int i = 0;i<n;i++) cout<<" "<<p[i];
        cout<<endl;
    }
}


0