結果

問題 No.2577 Simple Permutation Guess
ユーザー 👑 rin204rin204
提出日時 2023-12-05 01:44:50
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 3,739 bytes
コンパイル時間 3,559 ms
コンパイル使用メモリ 253,940 KB
実行使用メモリ 25,452 KB
平均クエリ数 248.84
最終ジャッジ日時 2024-09-26 23:54:27
合計ジャッジ時間 17,614 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,940 KB
testcase_01 AC 149 ms
24,812 KB
testcase_02 AC 50 ms
24,428 KB
testcase_03 AC 21 ms
24,428 KB
testcase_04 AC 62 ms
24,940 KB
testcase_05 AC 74 ms
25,452 KB
testcase_06 AC 188 ms
24,940 KB
testcase_07 AC 185 ms
24,556 KB
testcase_08 AC 180 ms
24,812 KB
testcase_09 AC 187 ms
24,796 KB
testcase_10 AC 187 ms
24,556 KB
testcase_11 AC 22 ms
25,196 KB
testcase_12 AC 22 ms
25,196 KB
testcase_13 AC 24 ms
24,940 KB
testcase_14 AC 25 ms
25,196 KB
testcase_15 AC 23 ms
24,428 KB
testcase_16 AC 22 ms
24,556 KB
testcase_17 AC 22 ms
24,812 KB
testcase_18 AC 21 ms
24,940 KB
testcase_19 AC 21 ms
24,940 KB
testcase_20 AC 22 ms
25,196 KB
testcase_21 AC 21 ms
24,556 KB
testcase_22 AC 22 ms
24,836 KB
testcase_23 AC 28 ms
24,836 KB
testcase_24 AC 22 ms
24,964 KB
testcase_25 AC 23 ms
25,220 KB
testcase_26 AC 22 ms
24,836 KB
testcase_27 AC 22 ms
25,220 KB
testcase_28 AC 22 ms
24,452 KB
testcase_29 AC 22 ms
24,836 KB
testcase_30 AC 22 ms
24,836 KB
testcase_31 AC 23 ms
24,428 KB
testcase_32 AC 22 ms
24,800 KB
testcase_33 AC 23 ms
24,940 KB
testcase_34 AC 22 ms
25,196 KB
testcase_35 AC 22 ms
24,812 KB
testcase_36 AC 23 ms
24,940 KB
testcase_37 AC 21 ms
24,580 KB
testcase_38 AC 20 ms
25,220 KB
testcase_39 AC 21 ms
24,452 KB
testcase_40 AC 26 ms
24,824 KB
testcase_41 AC 23 ms
25,076 KB
testcase_42 AC 28 ms
24,952 KB
testcase_43 AC 22 ms
24,836 KB
testcase_44 AC 22 ms
24,836 KB
testcase_45 AC 22 ms
24,452 KB
testcase_46 AC 21 ms
25,220 KB
testcase_47 AC 23 ms
24,836 KB
testcase_48 AC 21 ms
24,836 KB
testcase_49 AC 23 ms
24,964 KB
testcase_50 AC 23 ms
24,836 KB
testcase_51 AC 22 ms
24,964 KB
testcase_52 AC 22 ms
24,836 KB
testcase_53 AC 22 ms
25,220 KB
testcase_54 AC 23 ms
24,836 KB
testcase_55 AC 22 ms
24,452 KB
testcase_56 AC 22 ms
24,836 KB
testcase_57 AC 22 ms
25,220 KB
testcase_58 AC 21 ms
25,220 KB
testcase_59 AC 21 ms
24,452 KB
testcase_60 AC 26 ms
24,836 KB
testcase_61 AC 21 ms
25,220 KB
testcase_62 AC 21 ms
24,452 KB
testcase_63 AC 23 ms
24,452 KB
testcase_64 AC 22 ms
24,836 KB
testcase_65 AC 23 ms
25,348 KB
testcase_66 AC 22 ms
25,220 KB
testcase_67 AC 22 ms
24,836 KB
testcase_68 AC 22 ms
24,964 KB
testcase_69 AC 22 ms
24,964 KB
testcase_70 AC 23 ms
24,836 KB
testcase_71 AC 22 ms
24,580 KB
testcase_72 AC 22 ms
24,836 KB
testcase_73 AC 22 ms
24,428 KB
testcase_74 AC 24 ms
24,940 KB
testcase_75 AC 25 ms
24,812 KB
testcase_76 AC 24 ms
25,196 KB
testcase_77 AC 23 ms
24,812 KB
testcase_78 AC 23 ms
24,940 KB
testcase_79 AC 24 ms
25,064 KB
testcase_80 AC 25 ms
24,940 KB
testcase_81 AC 25 ms
24,940 KB
testcase_82 AC 25 ms
25,196 KB
testcase_83 AC 24 ms
24,812 KB
testcase_84 AC 24 ms
24,556 KB
testcase_85 AC 26 ms
24,940 KB
testcase_86 AC 24 ms
25,196 KB
testcase_87 AC 25 ms
25,184 KB
testcase_88 AC 26 ms
24,940 KB
testcase_89 AC 24 ms
24,940 KB
testcase_90 AC 25 ms
24,812 KB
testcase_91 AC 24 ms
24,812 KB
testcase_92 AC 154 ms
24,812 KB
testcase_93 AC 140 ms
24,812 KB
testcase_94 AC 128 ms
25,196 KB
testcase_95 AC 181 ms
24,556 KB
testcase_96 AC 177 ms
25,196 KB
testcase_97 AC 171 ms
25,184 KB
testcase_98 AC 163 ms
24,428 KB
testcase_99 AC 169 ms
24,812 KB
testcase_100 AC 131 ms
24,812 KB
testcase_101 AC 176 ms
24,812 KB
evil_1_rnd_1.txt AC 350 ms
24,556 KB
evil_1_rnd_2.txt AC 350 ms
24,812 KB
evil_2_big_1.txt AC 451 ms
24,812 KB
evil_2_big_2.txt AC 446 ms
24,812 KB
evil_2_big_3.txt AC 444 ms
24,940 KB
evil_3_sorted_1.txt AC 253 ms
24,568 KB
evil_4_sorted_rev_1.txt AC 190 ms
24,836 KB
evil_4_sorted_rev_2.txt AC 270 ms
24,964 KB
evil_400_sorted.txt AC 416 ms
24,824 KB
evil_400_sorted_rev.txt AC 425 ms
25,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <typename T>
struct BIT {
    int n;
    std::vector<T> tree;

    BIT(int n) : n(n) {
        tree.assign(n + 1, T(0));
    }
    BIT() {}
    T _sum(int i) {
        i++;
        T res = T(0);
        while (i > 0) {
            res += tree[i];
            i -= i & -i;
        }
        return res;
    }

    T sum(int l, int r) {
        return _sum(r - 1) - _sum(l - 1);
    }

    T sum(int r) {
        return _sum(r - 1);
    }

    T get(int i) {
        return _sum(i) - _sum(i - 1);
    }

    void add(int i, T x) {
        i++;
        while (i <= n) {
            tree[i] += x;
            i += i & -i;
        }
    }

    int lower_bound(T x) {
        int pos  = 0;
        int plus = 1;
        while (plus * 2 <= n) plus *= 2;
        while (plus > 0) {
            if ((pos + plus <= n) && (tree[pos + plus] < x)) {
                x -= tree[pos + plus];
                pos += plus;
            }
            plus >>= 1;
        }
        return pos;
    }
};

struct Factoradic : std::vector<int> {
    using std::vector<int>::vector;

    void shrink() {
        while (this->size() >= 2u && !this->back()) {
            this->pop_back();
        }
    }

    Factoradic &operator+=(const Factoradic &rhs) {
        this->resize(std::max(this->size(), rhs.size()) + 1);
        for (size_t i = 0; i < rhs.size(); ++i) {
            (*this)[i] += rhs[i];
        }
        for (size_t i = 0; i + 1 < this->size(); ++i) {
            if ((*this)[i] >= i + 1) {
                (*this)[i + 1] += (*this)[i] / (i + 1);
                (*this)[i] -= (i + 1);
            }
        }
        shrink();
        return *this;
    }
    Factoradic &operator/=(int rhs) {
        for (int i = int(this->size()) - 1; i >= 0; --i) {
            if (i) {
                (*this)[i - 1] += (*this)[i] % rhs * i;
            }
            (*this)[i] /= rhs;
        }
        shrink();
        return *this;
    }

    Factoradic operator+(const Factoradic &rhs) const {
        Factoradic ret = *this;
        ret += rhs;
        return ret;
    }
    Factoradic operator/(int rhs) const {
        Factoradic ret = *this;
        ret /= rhs;
        return ret;
    }

    std::vector<int> to_permutation(int digit = -1) const {
        if (digit == -1) digit = int(this->size());
        assert(int(this->size()) <= digit);
        BIT<int> bit(digit);
        for (int i = 0; i < digit; ++i) {
            bit.add(i, 1);
        }
        std::vector<int> ret;
        ret.reserve(digit);
        for (int i = digit - 1; i >= 0; --i) {
            int x = (i < this->size() ? (*this)[i] : 0);
            int p = bit.lower_bound(x + 1);
            ret.push_back(p);
            bit.add(p, -1);
        }
        return ret;
    }
};

void solve() {
    int n;
    cin >> n;
    Factoradic L(n + 1);
    Factoradic R(n + 1);
    R[n] = 1;
    L.shrink();
    R.shrink();
    while (1) {
        auto mid = (L + R) / 2;
        if (mid == L) break;
        auto P = mid.to_permutation(n);
        cout << "? ";
        for (size_t i = 0; i < P.size(); ++i) {
            cout << P[i] + 1;
            if (i != P.size() - 1) cout << " ";
        }
        cout << endl;
        int res;
        cin >> res;
        if (res == 0) {
            R = mid;
        } else {
            L = mid;
        }
    }
    auto P = L.to_permutation(n);
    cout << "! ";
    for (size_t i = 0; i < P.size(); ++i) {
        cout << P[i] + 1;
        if (i != P.size() - 1) cout << " ";
    }
    cout << endl;
}

int main() {
    // cin.tie(0)->sync_with_stdio(0);
    // cout << fixed << setprecision(12);
    int t;
    t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
0