結果

問題 No.1621 Sequence Inversions
ユーザー trineutrontrineutron
提出日時 2021-07-22 22:38:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 3,000 ms
コード長 1,358 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 213,048 KB
実行使用メモリ 5,460 KB
最終ジャッジ日時 2023-09-24 18:01:36
合計ジャッジ時間 4,727 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 37 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 40 ms
4,376 KB
testcase_09 AC 59 ms
4,540 KB
testcase_10 AC 119 ms
5,336 KB
testcase_11 AC 45 ms
4,380 KB
testcase_12 AC 94 ms
5,296 KB
testcase_13 AC 92 ms
5,460 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 27 ms
4,376 KB
testcase_17 AC 51 ms
4,452 KB
testcase_18 AC 25 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 57 ms
4,596 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 69 ms
4,844 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &&x : a)
    {
        cin >> x;
    }
    sort(a.begin(), a.end());
    auto acopy = a;
    acopy.erase(unique(acopy.begin(), acopy.end()), acopy.end());
    for (auto &&x : a)
    {
        x = lower_bound(acopy.begin(), acopy.end(), x) - acopy.begin();
    }
    vector<int> acount(n);
    for (auto &&x : a)
    {
        acount.at(x)++;
    }
    vector dp(n + 1, vector<mint>(k + 1));
    dp.at(0).at(0) = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            for (int jnew = j; jnew <= min(k, j + i); jnew++)
            {
                dp.at(i + 1).at(jnew) += dp.at(i).at(j);
            }
        }
    }
    auto ans = dp.at(n);
    for (int i = 0; i < n; i++)
    {
        int64_t d = acount.at(i);
        if (d <= 1)
        {
            continue;
        }
        for (int j = 0; j <= k; j++)
        {
            mint x = ans.at(j);
            for (int jnew = j + 1; jnew <= min(int64_t(k), j + d * (d - 1) / 2); jnew++)
            {
                ans.at(jnew) -= x * dp.at(d).at(jnew - j);
            }
        }
    }
    cout << ans.at(k).val() << endl;
    return 0;
}
0