結果

問題 No.2577 Simple Permutation Guess
ユーザー 👑 rin204rin204
提出日時 2023-12-05 01:42:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,707 bytes
コンパイル時間 3,717 ms
コンパイル使用メモリ 255,020 KB
実行使用メモリ 38,548 KB
平均クエリ数 106.80
最終ジャッジ日時 2023-12-05 01:42:30
合計ジャッジ時間 11,924 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,000 KB
testcase_01 AC 155 ms
24,000 KB
testcase_02 AC 50 ms
24,000 KB
testcase_03 AC 25 ms
24,000 KB
testcase_04 AC 68 ms
24,000 KB
testcase_05 AC 78 ms
24,000 KB
testcase_06 AC 191 ms
24,000 KB
testcase_07 AC 193 ms
24,000 KB
testcase_08 AC 191 ms
24,000 KB
testcase_09 AC 194 ms
24,000 KB
testcase_10 AC 217 ms
24,000 KB
testcase_11 AC 25 ms
24,000 KB
testcase_12 AC 25 ms
24,000 KB
testcase_13 AC 27 ms
24,000 KB
testcase_14 AC 25 ms
24,000 KB
testcase_15 AC 26 ms
24,000 KB
testcase_16 AC 25 ms
24,000 KB
testcase_17 AC 25 ms
24,000 KB
testcase_18 AC 25 ms
24,000 KB
testcase_19 AC 23 ms
24,000 KB
testcase_20 AC 24 ms
24,000 KB
testcase_21 AC 24 ms
24,000 KB
testcase_22 AC 24 ms
24,012 KB
testcase_23 AC 26 ms
24,012 KB
testcase_24 AC 24 ms
24,012 KB
testcase_25 AC 24 ms
24,012 KB
testcase_26 AC 26 ms
24,012 KB
testcase_27 AC 25 ms
24,012 KB
testcase_28 AC 26 ms
24,012 KB
testcase_29 AC 24 ms
24,012 KB
testcase_30 AC 24 ms
24,012 KB
testcase_31 AC 25 ms
24,000 KB
testcase_32 AC 25 ms
24,000 KB
testcase_33 AC 25 ms
24,000 KB
testcase_34 AC 25 ms
24,000 KB
testcase_35 AC 23 ms
24,000 KB
testcase_36 AC 24 ms
24,000 KB
testcase_37 AC 24 ms
24,000 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
evil_1_rnd_1.txt -- -
evil_1_rnd_2.txt -- -
evil_2_big_1.txt -- -
evil_2_big_2.txt -- -
evil_2_big_3.txt -- -
evil_3_sorted_1.txt -- -
evil_4_sorted_rev_1.txt -- -
evil_4_sorted_rev_2.txt -- -
evil_400_sorted.txt -- -
evil_400_sorted_rev.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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;
    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