結果

問題 No.2068 Restricted Permutation
ユーザー 遭難者遭難者
提出日時 2022-08-11 01:26:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,169 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 182,668 KB
実行使用メモリ 814,384 KB
最終ジャッジ日時 2023-08-08 14:02:21
合計ジャッジ時間 5,971 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 36 ms
11,720 KB
testcase_14 AC 134 ms
38,472 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
using namespace std;
using ll = long long;
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k, x;
    cin >> n >> k >> x;
    vector<mint> fa(n + 1);
    fa[0] = 1;
    rep(i, n) fa[i + 1] = (i + 1) * fa[i];
    vector<vector<mint>> d(k, vector<mint>(x));
    rep(j, x) d[k - 1][j] = fa[n - k] * fa[n - k] * j + fa[n - k] * (fa[n - k] - 1) / 2;
    for (int i = k - 2; i >= 0; i--)
    {
        d[i][0] = (n - i - 1) * (n - i) / 2 * fa[n - i - 1] * fa[n - i - 2] + (n - i - 1) * d[i + 1][0];
        for (int j = 1; j < x; j++)
            d[i][j] = ((n - i - 1) * (n - i) / 2 - j) * fa[n - i - 1] * fa[n - i - 2] + j * d[i + 1][j - 1] + (n - i - j - 1) * d[i + 1][j];
    }
    cout << d[0][x - 1].val() << endl;
    return 0;
}
0