結果

問題 No.1621 Sequence Inversions
ユーザー KudeKude
提出日時 2021-07-22 22:44:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,451 ms / 3,000 ms
コード長 1,663 bytes
コンパイル時間 4,318 ms
コンパイル使用メモリ 267,816 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-09-24 18:19:08
合計ジャッジ時間 10,516 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,328 KB
testcase_01 AC 5 ms
7,368 KB
testcase_02 AC 5 ms
7,472 KB
testcase_03 AC 5 ms
7,552 KB
testcase_04 AC 8 ms
7,480 KB
testcase_05 AC 4 ms
7,364 KB
testcase_06 AC 5 ms
7,360 KB
testcase_07 AC 5 ms
7,480 KB
testcase_08 AC 40 ms
7,336 KB
testcase_09 AC 56 ms
7,376 KB
testcase_10 AC 97 ms
7,492 KB
testcase_11 AC 43 ms
7,412 KB
testcase_12 AC 258 ms
7,368 KB
testcase_13 AC 497 ms
7,368 KB
testcase_14 AC 29 ms
7,388 KB
testcase_15 AC 27 ms
7,412 KB
testcase_16 AC 259 ms
7,400 KB
testcase_17 AC 781 ms
7,408 KB
testcase_18 AC 233 ms
7,624 KB
testcase_19 AC 5 ms
7,372 KB
testcase_20 AC 119 ms
7,536 KB
testcase_21 AC 1,001 ms
7,348 KB
testcase_22 AC 68 ms
7,424 KB
testcase_23 AC 1,451 ms
7,404 KB
testcase_24 AC 5 ms
7,392 KB
testcase_25 AC 5 ms
7,380 KB
testcase_26 AC 5 ms
7,396 KB
testcase_27 AC 5 ms
7,404 KB
testcase_28 AC 4 ms
7,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

mint dp0[101][10010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int s = 0; s <= 100; s++) for(int cnt = 0; cnt <= 100; cnt++) {
    }
    int n, k;
    cin >> n >> k;
    map<int, int> hist;
    rep(i, n) {
        int a;
        cin >> a;
        hist[a]++;
    }
    int s = 0;
    vector<mint> dp(k + 1);
    dp[0] = 1;
    for(auto [_, cnt]: hist) {
        for(int i = cnt; i >= 0; i--) for(int j = k; j >= 0; j--) {
            dp0[i][j] = 0;
        }
        dp0[0][0] = 1;
        for(int r = 0; r <= s; r++) for(int i = cnt; i >= 0; i--) for(int j = k; j >= 0; j--) {
            mint now = dp0[i][j];
            if (now == 0) continue;
            dp0[i][j] = 0;
            for(int ni = i; ni <= cnt; ni++) {
                int add = ni - i;
                dp0[ni][j + r * add] += now;
            }
        }
        for(int i = k; i >= 0; i--) {
            mint now = dp[i];
            dp[i] = 0;
            for(int j = k - i; j >= 0; j--) dp[i + j] += now * dp0[cnt][j];
        }
        s += cnt;
    }
    cout << dp[k].val() << endl;
}
0