結果

問題 No.1311 Reverse Permutation Index
ユーザー merom686merom686
提出日時 2020-12-08 01:38:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,001 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 89,784 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 16:50:29
合計ジャッジ時間 1,260 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll k;
    cin >> k;

    int n;
    cin >> n;

    vector<int> p(n), q(n);
    for (int i = n; --i >= 0;) {
        int b = n - i;
        p[i] = k % b; k /= b;
    }
    vector<int> o(n, 0);
    for (int i = 0; i < n; i++) {
        int t = p[i];
        for (int j = 0; j < n; j++) {
            if (o[j] == 0 && t-- == 0) {
                o[p[i] = j] = 1;
                break;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        q[p[i]] = i;
    }
    o.assign(n, 0);
    for (int i = 0; i < n; i++) {
        int t = 0;
        for (int j = q[i]; --j >= 0;) {
            t += o[j] == 0;
        }
        o[q[i]] = 1;
        q[i] = t;
    }
    for (int i = 0; i < n; i++) {
        int b = n - i;
        k *= b;
        k += q[i];
    }

    cout << k << endl;

    return 0;
}
0