結果

問題 No.3347 Guess The Array
コンテスト
ユーザー ponjuice
提出日時 2025-10-25 11:38:09
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 1,292 bytes
コンパイル時間 3,031 ms
コンパイル使用メモリ 282,296 KB
実行使用メモリ 25,984 KB
平均クエリ数 3924.07
最終ジャッジ日時 2025-11-13 20:51:11
合計ジャッジ時間 19,741 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool query(const vector<int>& q) {
    cout << "? " << q.size() << " ";
    for(int i = 0; i < q.size(); i++) {
        cout << q[i] << " \n"[i==q.size()-1];
    }
    cout << flush;
    string s;
    cin >> s;
    return s == "Yes";
}

int n;
void answer(const vector<int>& ans) {
    assert(ans.size() == n);
    cout << "! ";
    for(int i = 0; i < n; i++) {
        cout << ans[i] << " \n"[i==n-1];
    }
    cout << flush;
}

int main() {
    cin >> n;

    vector<int> ans;
    for(int i = 1; i <= n; i++) {
        vector<int> pos;
        for(int cnt = 1; cnt <= n; cnt++) {
            if(!query(vector<int>(cnt, i))) break;

            // 最後から cnt 個目の i が挿入される場所の二分探索
            int ok = 0, ng = ans.size() + 1;
            while(ng - ok > 1) {
                int mid = (ok + ng) / 2;

                vector<int> q;
                for(int j = 0; j < mid; j++) q.push_back(ans[j]);
                for(int j = 0; j < cnt; j++) q.push_back(i);
                
                if(query(q)) ok = mid;
                else ng = mid;
            }

            pos.push_back(ok);
        }
        for(auto p: pos) {
            ans.insert(ans.begin() + p, i);
        }
    }

    answer(ans);
}
0