結果

問題 No.3592 I Love LIS
コンテスト
ユーザー otoshigo
提出日時 2026-07-17 22:33:37
言語 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,263 ms / 8,000 ms
+ 13µs
コード長 2,927 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,588 ms
コンパイル使用メモリ 338,032 KB
実行使用メモリ 5,888 KB
平均クエリ数 4272.69
最終ジャッジ日時 2026-07-17 22:33:59
合計ジャッジ時間 21,829 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }

template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_heap = priority_queue<T>;

void solve() {
    int N;
    cin >> N;
    vector<int> P(N, -1);
    rep(i, 0, N) {
        vector<int> A(N);
        rep(j, 0, N) {
            if (j == i) A[j] = 2;
            else A[j] = 1;
        }
        cout << "? ";
        rep(j, 0, N) cout << A[j] << " ";
        cout << endl;
        int l;
        cin >> l;
        assert(l >= 0);
        if (l == 1) {
            P[0] = i;
            break;
        }
    }
    auto comp = [&](int x, int y) -> bool {
        vector<int> A(N);
        A[P[0]] = 1;
        rep(i, 0, N) {
            if (i == P[0]) continue;
            if (i == x) A[i] = 2;
            else if (i == y) A[i] = 3;
            else A[i] = 1;
        }
        cout << "? ";
        rep(j, 0, N) cout << A[j] << " ";
        cout << endl;
        int l;
        cin >> l;
        assert(l >= 0);
        if (x < y && l == 3) return true;
        if (x > y && l == 2) return true;
        return false;
    };
    auto merge_sort = [&](auto self, vector<int> &V) -> void {
        int S = V.size();
        if (S <= 1) return;
        vector<int> L, R;
        rep(i, 0, S / 2) L.push_back(V[i]);
        rep(i, S / 2, S) R.push_back(V[i]);
        self(self, L);
        self(self, R);
        V.clear();
        int s = 0, t = 0;
        while (s < L.size() || t < R.size()) {
            if (s < L.size() && t < R.size()) {
                if (comp(L[s], R[t])) {
                    V.push_back(L[s]);
                    s++;
                } else {
                    V.push_back(R[t]);
                    t++;
                }
            } else if (s == L.size()) {
                V.push_back(R[t]);
                t++;
            } else {
                V.push_back(L[s]);
                s++;
            }
        }
    };
    vector<int> V;
    rep(i, 0, N) if (i != P[0]) V.push_back(i);
    merge_sort(merge_sort, V);
    rep(i, 0, N - 1) P[i + 1] = V[i];
    // vector<int> Q(N);
    // rep(i, 0, N) Q[P[i]] = i;
    cout << "! ";
    rep(i, 0, N) cout << P[i] + 1 << " ";
    cout << endl;
}

int main() {
    // cin.tie(0)->sync_with_stdio(0);
    // cout << fixed << setprecision(15);
    srand(time(NULL));

    int T;
    // cin >> T;
    T = 1;
    while (T--) solve();
}
0