結果

問題 No.1621 Sequence Inversions
ユーザー 👑 hitonanodehitonanode
提出日時 2021-07-22 22:04:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 3,000 ms
コード長 1,487 bytes
コンパイル時間 2,771 ms
コンパイル使用メモリ 140,544 KB
実行使用メモリ 4,464 KB
最終ジャッジ日時 2023-09-24 17:04:08
合計ジャッジ時間 4,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 21 ms
4,464 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 34 ms
4,376 KB
testcase_13 AC 36 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 AC 13 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 26 ms
4,376 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 32 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

#include <atcoder/modint>
#include <atcoder/convolution>
using mint = atcoder::modint998244353;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto &a : A) cin >> a;
    map<int, int> mp;
    for (auto a : A) mp[a]++;
    int n = 0;
    auto compare = [&](const vector<mint> &l, const vector<mint> &r) { return l.size() > r.size(); };
    priority_queue<vector<mint>, vector<vector<mint>>, decltype(compare)> pq{compare};
    pq.emplace(vector<mint>{1});

    for (auto [k, cnt] : mp) {
        vector dp(cnt + 1, vector<mint>(K + 1));
        dp[0][0] = 1;
        REP(t, n + 1) {
            REP(iuse, dp.size() - 1) REP(k, int(dp[iuse].size()) - t) if (dp[iuse][k].val()) {
                dp[iuse + 1][k + t] += dp[iuse][k];
            }
        }
        auto v = dp.back();
        while (v.size() and v.back() == 0) v.pop_back();
        pq.emplace(v);
        n += cnt;
    }

    while (pq.size() > 1) {
        auto f1 = pq.top();
        pq.pop();
        auto f2 = pq.top();
        pq.pop();
        auto f = atcoder::convolution(f1, f2);
        if (f.size() > K) f.resize(K + 1);
        pq.emplace(f);
    }
    auto f = pq.top();
    cout << (int(f.size()) > K ? f[K] : 0).val() << '\n';
}
0