結果

問題 No.1621 Sequence Inversions
ユーザー ぷらぷら
提出日時 2021-11-30 23:03:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,563 ms / 3,000 ms
コード長 2,026 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 208,004 KB
実行使用メモリ 11,348 KB
最終ジャッジ日時 2023-09-16 21:10:21
合計ジャッジ時間 16,888 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 17 ms
6,940 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 276 ms
7,092 KB
testcase_09 AC 200 ms
8,208 KB
testcase_10 AC 443 ms
11,228 KB
testcase_11 AC 297 ms
7,452 KB
testcase_12 AC 1,137 ms
11,156 KB
testcase_13 AC 1,445 ms
11,348 KB
testcase_14 AC 223 ms
5,160 KB
testcase_15 AC 229 ms
4,800 KB
testcase_16 AC 733 ms
6,472 KB
testcase_17 AC 1,794 ms
8,408 KB
testcase_18 AC 683 ms
6,576 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 207 ms
5,204 KB
testcase_21 AC 2,120 ms
9,096 KB
testcase_22 AC 397 ms
5,412 KB
testcase_23 AC 2,563 ms
10,028 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
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