結果

問題 No.3592 I Love LIS
コンテスト
ユーザー tkdgkb
提出日時 2026-07-17 21:46:22
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,362 ms / 8,000 ms
+ 14µs
コード長 1,124 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,327 ms
コンパイル使用メモリ 178,776 KB
実行使用メモリ 5,888 KB
平均クエリ数 4697.25
最終ジャッジ日時 2026-07-17 21:47:13
合計ジャッジ時間 21,709 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
int N;
int ask(const vector<int>& a) {
    cout << "?";
    for (int x : a) {
        cout << " " << x;
    }
    cout << "\n";
    cout.flush();

    int res;
    cin >> res;
    if (res == -1) exit(0);
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N; 
    int p1 = -1;
    for (int x = 1; x < N; ++x) {
        vector<int> a(N, 1);
        a[x - 1] = 2;
        
        int lis = ask(a);
        if (lis == 1) { 
            p1 = x;
            break;
        }
    }
    if (p1 == -1) {
        p1 = N; 
    }

    vector<int> rem;
    for (int i = 1; i <= N; ++i) {
        if (i != p1) rem.push_back(i);
    }

    auto cmp = [&](int x, int y) {
        vector<int> a(N, 0);
        a[x - 1] = 1;
        a[y - 1] = 2;
        
        int lis = ask(a);
        return lis == 3;
    };

    stable_sort(rem.begin(), rem.end(), cmp);

    cout << "! " << p1;
    for (int x : rem) {
        cout << " " << x;
    }
    cout << "\n";
    cout.flush();

    return 0;
}
0