結果

問題 No.1621 Sequence Inversions
ユーザー ぷらぷら
提出日時 2021-11-30 22:47:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,869 bytes
コンパイル時間 3,268 ms
コンパイル使用メモリ 204,144 KB
実行使用メモリ 11,444 KB
最終ジャッジ日時 2023-09-16 20:42:59
合計ジャッジ時間 22,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1,556 ms
11,140 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 280 ms
5,100 KB
testcase_15 AC 269 ms
4,792 KB
testcase_16 AC 845 ms
6,616 KB
testcase_17 AC 2,167 ms
8,624 KB
testcase_18 AC 762 ms
6,284 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 213 ms
5,280 KB
testcase_21 AC 2,501 ms
9,072 KB
testcase_22 AC 454 ms
5,320 KB
testcase_23 TLE -
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int mod = 998244353;
long long dp[2][102][5005];

int main() {
    int n,K;
    cin >> n >> K;
    vector<int>a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    dp[0][0][0] = 1;
    for(int i = 1; i < n; i++) {
        if(a[i-1] == a[i]) {
            for(int j = 0; j < n; j++) {
                for(int k = 0; k <= K; k++) {
                    for(int l = j; l < i; l++) {
                        if(k+l <= K) {
                            dp[1][l][k+l] += dp[0][j][k];
                            if(dp[1][l][k+l] >= mod) {
                                dp[1][l][k+l] -= mod;
                            }
                        }
                    }
                }
            }
            for(int j = 0; j < n; j++) {
                for(int k = 0; k <= K; k++) {
                    dp[0][j][k] = dp[1][j][k];
                    dp[1][j][k] = 0;
                }
            }
        }
        else {
            for(int j = 0; j < n; j++) {
                for(int k = 0; k <= K; k++) {
                    for(int l = 0; l <= i; l++) {
                        if(k+l <= K) {
                            dp[1][l][k+l] += dp[0][j][k];
                            if(dp[1][l][k+l] >= mod) {
                                dp[1][l][k+l] -= mod;
                            }
                        }
                    }
                }
            }
            for(int j = 0; j < n; j++) {
                for(int k = 0; k <= K; k++) {
                    dp[0][j][k] = dp[1][j][k];
                    dp[1][j][k] = 0;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans += dp[0][i][K];
        if(ans >= mod) {
            ans -= mod;
        }
    }
    cout << ans << endl;
}
0