結果

問題 No.1621 Sequence Inversions
ユーザー ぷらぷら
提出日時 2021-11-30 22:53:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,914 bytes
コンパイル時間 2,965 ms
コンパイル使用メモリ 204,808 KB
実行使用メモリ 11,304 KB
最終ジャッジ日時 2023-09-16 20:55:30
合計ジャッジ時間 13,508 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,500 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 30 ms
6,908 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 85 ms
11,168 KB
testcase_11 WA -
testcase_12 AC 119 ms
11,176 KB
testcase_13 AC 200 ms
11,304 KB
testcase_14 WA -
testcase_15 AC 263 ms
5,096 KB
testcase_16 AC 779 ms
6,492 KB
testcase_17 AC 2,053 ms
8,484 KB
testcase_18 AC 734 ms
6,284 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 212 ms
5,256 KB
testcase_21 AC 2,431 ms
9,068 KB
testcase_22 AC 453 ms
5,320 KB
testcase_23 TLE -
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    int cnt = 0;
    for(int i = 1; i < n; i++) {
        if(a[i-1] == a[i]) {
            cnt++;
            for(int j = 0; j < n; j++) {
                for(int k = 0; k <= K; k++) {
                    for(int l = j; l <= i-cnt; 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-cnt; 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