結果

問題 No.2577 Simple Permutation Guess
ユーザー fdironiafdironia
提出日時 2023-12-06 00:06:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,022 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 89,096 KB
実行使用メモリ 38,548 KB
平均クエリ数 0.07
最終ジャッジ日時 2023-12-06 00:06:30
合計ジャッジ時間 6,811 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
24,000 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
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 <iostream>
#include <algorithm>

using namespace std;

constexpr int L = 871;
constexpr int LGN = 9;

struct BI {
    int a[L];

    BI(int x = 0) {
        fill(a, a + L, 0);
        for (int i = 0; x; i++, x /= 10) {
            a[i] = x % 10;
        }
    }
};

BI& operator*=(BI &a, int b) {
    for (int i = 0; i < L; i++) {
        a.a[i] *= b;
    }
    for (int i = 0; i < L - 1; i++) {
        a.a[i+1] += a.a[i] / 10;
        a.a[i] %= 10;
    }
    return a;
}

BI operator-(const BI &a, const BI &b) {
    BI c = 0;
    for (int i = 0; i < L; i++) {
        c.a[i] = a.a[i] - b.a[i];
    }
    for (int i = 0; i < L - 1; i++) {
        if (c.a[i] < 0) {
            c.a[i+1]--;
            c.a[i] += 10;
        }
    }
    return c;
}

BI operator+(const BI &a, const BI &b) {
    BI c = 0;
    for (int i = 0; i < L; i++) {
        c.a[i] = a.a[i] + b.a[i];
    }
    for (int i = 0; i < L - 1; i++) {
        if (c.a[i] >= 10) {
            c.a[i+1]++;
            c.a[i] -= 10;
        }
    }
    return c;
}

BI& operator/=(BI &a, int b) {
    for (int i = L - 1, q = 0; i >= 0; i--) {
        q = q * 10 + a.a[i];
        a.a[i] = q / b;
        q %= b;
    }
    return a;
}

int operator%(const BI &a, int b) {
    int q = 0;
    for (int i = L - 1; i >= 0; i--) {
        q = (q * 10 + a.a[i]) % b;
    }
    return q;
}

bool operator>(const BI &a, const BI &b) {
    for (int i = L - 1; i >= 0; i--) {
        if (a.a[i] != b.a[i]) {
            return a.a[i] > b.a[i];
        }
    }
    return false;
}

void add(int bit[], int n, int x, int a) {
    for (; x <= n; x += x & -x) {
        bit[x] += a;
    }
}

int qry(int bit[], int n, int v) {
    int x = 0, cur = 0;
    for (int i = LGN - 1; i >= 0; i--) {
        if (x + (1 << i) <= n) {
            if (cur + bit[x+(1<<i)] <= v) {
                cur += bit[x+(1<<i)];
                x += 1 << i;
            }
        }
    }
    return x + 1;
}

void find_perm(BI a, int n, int p[]) {
    for (int i = 0; i < n; i++) {
        p[i] = a % (i + 1);
        a /= i + 1;
    }

    int bit[n+1];
    fill(bit, bit + n + 1, 0);
    for (int i = 1; i <= n; i++) {
        add(bit, n, i, 1);
    }

    for (int i = n - 1; i >= 0; i--) {
        p[i] = qry(bit, n, p[i]);
        add(bit, n, p[i], -1);
    }

    reverse(p, p + n);
}

int main() {
    int n;
    cin >> n;

    BI l = 0, r = 1;
    for (int i = 1; i <= n; i++) {
        r *= i;
    }
    r = r - 1;

    BI one = 1;
    while (r - l > one) {
        BI mid = l + r;
        mid /= 2;

        int q[n];
        find_perm(mid, n, q);

        cout << "?";
        for (int i = 0; i < n; i++) {
            cout << " " << q[i];
        }
        cout << endl;

        int res;
        cin >> res;

        if (res == 1) {
            l = mid;
        } else {
            r = mid;
        }
    }

    int ans[n];
    find_perm(l, n, ans);

    cout << "!";
    for (int i = 0; i < n; i++) {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}
0