結果

問題 No.2577 Simple Permutation Guess
ユーザー t98slidert98slider
提出日時 2023-12-05 02:45:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 2,975 bytes
コンパイル時間 2,562 ms
コンパイル使用メモリ 211,236 KB
実行使用メモリ 24,012 KB
平均クエリ数 248.84
最終ジャッジ日時 2023-12-05 02:45:37
合計ジャッジ時間 30,702 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,000 KB
testcase_01 AC 323 ms
24,000 KB
testcase_02 AC 61 ms
24,000 KB
testcase_03 AC 24 ms
24,000 KB
testcase_04 AC 95 ms
24,000 KB
testcase_05 AC 120 ms
24,000 KB
testcase_06 AC 481 ms
24,000 KB
testcase_07 AC 462 ms
24,000 KB
testcase_08 AC 471 ms
24,000 KB
testcase_09 AC 459 ms
24,000 KB
testcase_10 AC 462 ms
24,000 KB
testcase_11 AC 26 ms
24,000 KB
testcase_12 AC 23 ms
24,000 KB
testcase_13 AC 27 ms
24,000 KB
testcase_14 AC 25 ms
24,000 KB
testcase_15 AC 23 ms
24,000 KB
testcase_16 AC 23 ms
24,000 KB
testcase_17 AC 24 ms
24,000 KB
testcase_18 AC 22 ms
24,000 KB
testcase_19 AC 23 ms
24,000 KB
testcase_20 AC 23 ms
24,000 KB
testcase_21 AC 23 ms
24,000 KB
testcase_22 AC 23 ms
24,012 KB
testcase_23 AC 23 ms
24,012 KB
testcase_24 AC 24 ms
24,012 KB
testcase_25 AC 23 ms
24,012 KB
testcase_26 AC 23 ms
24,012 KB
testcase_27 AC 23 ms
24,012 KB
testcase_28 AC 23 ms
24,012 KB
testcase_29 AC 24 ms
24,012 KB
testcase_30 AC 22 ms
24,012 KB
testcase_31 AC 28 ms
24,000 KB
testcase_32 AC 24 ms
24,000 KB
testcase_33 AC 24 ms
24,000 KB
testcase_34 AC 23 ms
24,000 KB
testcase_35 AC 24 ms
24,000 KB
testcase_36 AC 24 ms
24,000 KB
testcase_37 AC 23 ms
24,000 KB
testcase_38 AC 22 ms
24,000 KB
testcase_39 AC 23 ms
24,000 KB
testcase_40 AC 23 ms
24,000 KB
testcase_41 AC 23 ms
24,000 KB
testcase_42 AC 23 ms
24,000 KB
testcase_43 AC 23 ms
24,000 KB
testcase_44 AC 24 ms
24,000 KB
testcase_45 AC 23 ms
24,000 KB
testcase_46 AC 24 ms
24,000 KB
testcase_47 AC 25 ms
24,000 KB
testcase_48 AC 25 ms
24,000 KB
testcase_49 AC 23 ms
24,000 KB
testcase_50 AC 26 ms
24,000 KB
testcase_51 AC 25 ms
24,000 KB
testcase_52 AC 24 ms
24,000 KB
testcase_53 AC 24 ms
24,000 KB
testcase_54 AC 24 ms
24,000 KB
testcase_55 AC 24 ms
24,000 KB
testcase_56 AC 24 ms
24,000 KB
testcase_57 AC 23 ms
24,000 KB
testcase_58 AC 23 ms
24,000 KB
testcase_59 AC 23 ms
24,000 KB
testcase_60 AC 23 ms
24,000 KB
testcase_61 AC 24 ms
24,000 KB
testcase_62 AC 24 ms
24,000 KB
testcase_63 AC 24 ms
24,000 KB
testcase_64 AC 23 ms
24,012 KB
testcase_65 AC 24 ms
24,012 KB
testcase_66 AC 24 ms
24,012 KB
testcase_67 AC 24 ms
24,012 KB
testcase_68 AC 24 ms
24,012 KB
testcase_69 AC 25 ms
24,012 KB
testcase_70 AC 23 ms
24,012 KB
testcase_71 AC 24 ms
24,012 KB
testcase_72 AC 24 ms
24,012 KB
testcase_73 AC 23 ms
24,000 KB
testcase_74 AC 27 ms
24,000 KB
testcase_75 AC 26 ms
24,000 KB
testcase_76 AC 27 ms
24,000 KB
testcase_77 AC 25 ms
24,000 KB
testcase_78 AC 25 ms
24,000 KB
testcase_79 AC 25 ms
24,000 KB
testcase_80 AC 26 ms
24,000 KB
testcase_81 AC 25 ms
24,000 KB
testcase_82 AC 26 ms
24,000 KB
testcase_83 AC 26 ms
24,000 KB
testcase_84 AC 26 ms
24,000 KB
testcase_85 AC 26 ms
24,000 KB
testcase_86 AC 27 ms
24,000 KB
testcase_87 AC 27 ms
24,012 KB
testcase_88 AC 29 ms
24,012 KB
testcase_89 AC 26 ms
24,012 KB
testcase_90 AC 26 ms
24,012 KB
testcase_91 AC 26 ms
24,012 KB
testcase_92 AC 330 ms
24,012 KB
testcase_93 AC 285 ms
24,012 KB
testcase_94 AC 261 ms
24,012 KB
testcase_95 AC 430 ms
24,012 KB
testcase_96 AC 431 ms
24,012 KB
testcase_97 AC 400 ms
24,012 KB
testcase_98 AC 381 ms
24,012 KB
testcase_99 AC 407 ms
24,012 KB
testcase_100 AC 291 ms
24,012 KB
testcase_101 AC 395 ms
24,012 KB
evil_1_rnd_1.txt AC 1,257 ms
24,012 KB
evil_1_rnd_2.txt AC 1,270 ms
24,012 KB
evil_2_big_1.txt AC 1,805 ms
24,012 KB
evil_2_big_2.txt AC 1,820 ms
24,012 KB
evil_2_big_3.txt AC 1,810 ms
24,012 KB
evil_3_sorted_1.txt AC 584 ms
24,012 KB
evil_4_sorted_rev_1.txt AC 383 ms
24,012 KB
evil_4_sorted_rev_2.txt AC 659 ms
24,012 KB
evil_400_sorted.txt AC 1,262 ms
24,012 KB
evil_400_sorted_rev.txt AC 1,224 ms
24,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

struct factint {
    int n;
    std::vector<int> dat;
    factint() : n(0), dat(0) {}
    factint(int _n) : n(_n), dat(n) {}
    void safe(int st){
        for(int i = st; i + 1 < n; i++){
            if(dat[i] >= i + 1){
                dat[i + 1] += dat[i] / (i + 1);
                dat[i] %= i + 1;
            }
        }
    }
    factint& operator+=(const factint& rhs) { 
        for(int i = 0; i < n; i++){
            dat[i] += rhs.dat[i];
        }
        safe(0);
        return *this; 
    }
    factint& operator/=(const int v) {
        std::vector<int> rep(n);
        for(int i = n - 1; i >= 0; i--){
            int to = i, tmp = dat[i];
            while(to >= 1 && tmp % v != 0) tmp *= to--;
            rep[to] += tmp / v;
        }
        swap(dat, rep);
        safe(0);
        return *this;
    }
    factint operator+() const { return *this; }
    friend factint operator+(const factint& lhs, const factint& rhs) { return factint(lhs) += rhs; }
    friend factint operator/(const factint& lhs, const int& rhs) { return factint(lhs) /= rhs; }
    friend bool operator < (const factint& lhs, const factint& rhs) {
        for(int i = lhs.n - 1; i >= 0; i--){
            if(lhs.dat[i] < rhs.dat[i]) return true;
        }
        return false;
    }
    friend std::ostream& operator << (std::ostream &os, const factint& rhs) noexcept {
        int n = rhs.n;
        std::vector<bool> used(n);
        for(int i = n - 1; i >= 0; i--){
            int c = rhs.dat[i];
            for(int j = 0; j < n; j++){
                if(used[j]) continue;
                if(c == 0){
                    if(i != n - 1) os << ' ';
                    os << j + 1;
                    used[j] = true;
                }
                c--;
            }
        }
        return os;
    }
    std::vector<int> get(){
        std::vector<bool> used(n);
        std::vector<int> ans(n);
        for(int i = n - 1; i >= 0; i--){
            int c = dat[i];
            for(int j = 0; j < n; j++){
                if(used[j]) continue;
                if(c == 0){
                    ans[n - 1 - i] = j + 1;
                    used[j] = true;
                }
                c--;
            }
        }
        return ans;
    }
};

vector<int> rhs = {1, 2, 5, 3, 4};
bool check(vector<int> lhs){
    cerr << lhs << '\n';
    return lhs <= rhs;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, v;
    cin >> n;
    factint ok(n), ng(n), mid(n), one(n);
    ng.dat[n - 1] = n;
    one.dat[0] = 1;
    while(ok + one < ng){
        mid = (ok + ng) / 2;
        cout << "? " << mid << endl;
        cin >> v;
        (v ? ok : ng) = mid;
    }
    cout << "! " << ok << endl;
}
0