結果

問題 No.1621 Sequence Inversions
ユーザー ぷらぷら
提出日時 2021-11-30 23:01:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,935 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 206,408 KB
実行使用メモリ 11,240 KB
最終ジャッジ日時 2023-09-16 21:08:04
合計ジャッジ時間 19,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 38 ms
6,916 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 363 ms
7,064 KB
testcase_09 AC 296 ms
8,124 KB
testcase_10 AC 695 ms
11,192 KB
testcase_11 AC 404 ms
7,356 KB
testcase_12 AC 1,647 ms
11,204 KB
testcase_13 AC 2,055 ms
11,240 KB
testcase_14 AC 272 ms
5,184 KB
testcase_15 AC 273 ms
4,832 KB
testcase_16 AC 864 ms
6,412 KB
testcase_17 AC 2,205 ms
8,640 KB
testcase_18 AC 792 ms
6,492 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 225 ms
5,204 KB
testcase_21 AC 2,654 ms
9,044 KB
testcase_22 AC 477 ms
5,292 KB
testcase_23 TLE -
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 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;
    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 {
            cnt = 0;
            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