結果

問題 No.1621 Sequence Inversions
ユーザー だれだれ
提出日時 2021-07-12 22:57:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 3,000 ms
コード長 1,425 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 87,484 KB
実行使用メモリ 104,864 KB
最終ジャッジ日時 2023-09-24 15:09:35
合計ジャッジ時間 5,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
103,052 KB
testcase_01 AC 61 ms
103,012 KB
testcase_02 AC 64 ms
103,108 KB
testcase_03 AC 61 ms
103,056 KB
testcase_04 AC 62 ms
102,960 KB
testcase_05 AC 61 ms
102,956 KB
testcase_06 AC 62 ms
103,148 KB
testcase_07 AC 65 ms
103,032 KB
testcase_08 AC 108 ms
103,028 KB
testcase_09 AC 88 ms
103,120 KB
testcase_10 AC 88 ms
103,004 KB
testcase_11 AC 107 ms
103,108 KB
testcase_12 AC 121 ms
103,136 KB
testcase_13 AC 127 ms
103,368 KB
testcase_14 AC 132 ms
103,500 KB
testcase_15 AC 132 ms
104,864 KB
testcase_16 AC 122 ms
104,376 KB
testcase_17 AC 132 ms
104,564 KB
testcase_18 AC 120 ms
104,328 KB
testcase_19 AC 66 ms
103,080 KB
testcase_20 AC 93 ms
104,152 KB
testcase_21 AC 132 ms
104,832 KB
testcase_22 AC 134 ms
104,512 KB
testcase_23 AC 133 ms
104,512 KB
testcase_24 AC 63 ms
103,104 KB
testcase_25 AC 63 ms
103,044 KB
testcase_26 AC 62 ms
103,048 KB
testcase_27 AC 62 ms
103,036 KB
testcase_28 AC 62 ms
103,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <atcoder/modint>

using namespace std;
using mint = atcoder::modint998244353;

mint f[101][101][2501];

int main(){
    for (int i = 0; i < 101; i++){
        f[0][i][0] = 1;
    }
    for (int n = 1; n < 101; n++){
        for (int k = 0; k < 101; k++){
            for (int m = 0; m < 2501; m++){
                if (n * k < m){
                    break;
                }
                f[n][k][m] += f[n - 1][k][m];
                if (m - n >= 0 && k > 0){
                    f[n][k][m] += f[n][k - 1][m - n];
                }
            }
        }
    }
    int t, k;
    cin >> t >> k;
    vector<int> a(t);
    for (int i = 0; i < t; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    vector<int> cnt(100);
    int n = 0;
    for (int i = 0; i < t - 1; i++){
        cnt[n]++;
        if (a[i] != a[i + 1]){
            n++;
        }
    }
    cnt[n++]++;

    vector dp(n + 1, vector<mint>(5000, 0));
    dp[0][0] = 1;
    int cursum = 0;

    for (int i = 1; i <= n; i++){
        auto x = cnt[i - 1];
        for (int j = 0; j < 5000; j++){
            for (int l = 0; l <= cursum * x; l++){
                if (j - l < 0){
                    break;
                }
                dp[i][j] += f[x][cursum][l] * dp[i - 1][j - l];
            }
        }
        cursum += x;
    }

    cout << dp[n][k].val() << endl;
}
0