結果

問題 No.1621 Sequence Inversions
ユーザー risujirohrisujiroh
提出日時 2021-07-22 22:02:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,081 ms / 3,000 ms
コード長 1,027 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 218,448 KB
実行使用メモリ 402,032 KB
最終ジャッジ日時 2023-09-24 17:01:13
合計ジャッジ時間 22,461 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 7 ms
8,132 KB
testcase_04 AC 377 ms
314,776 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 10 ms
10,112 KB
testcase_08 AC 527 ms
402,012 KB
testcase_09 AC 483 ms
401,944 KB
testcase_10 AC 486 ms
402,008 KB
testcase_11 AC 520 ms
402,012 KB
testcase_12 AC 623 ms
401,948 KB
testcase_13 AC 808 ms
402,016 KB
testcase_14 AC 1,234 ms
402,032 KB
testcase_15 AC 2,014 ms
402,004 KB
testcase_16 AC 1,377 ms
289,428 KB
testcase_17 AC 1,958 ms
386,452 KB
testcase_18 AC 1,305 ms
277,020 KB
testcase_19 AC 4 ms
4,776 KB
testcase_20 AC 311 ms
84,276 KB
testcase_21 AC 2,073 ms
401,940 KB
testcase_22 AC 2,081 ms
401,868 KB
testcase_23 AC 2,053 ms
402,012 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto&& e : a) cin >> e;
  sort(begin(a), end(a), greater{});
  using Fp = atcoder::modint998244353;
  vector c(n, vector(n + 1, vector<Fp>(n * n + 1)));
  c[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    if (i) c[i] = c[i - 1];
    for (int j = 0; j < n; ++j)
      for (int k = 0; k + i <= n * n; ++k) c[i][j + 1][k + i] += c[i][j][k];
  }
  vector<Fp> f{1};
  for (int l = 0; l < int(size(a));) {
    int r = l;
    while (r < n && a[r] == a[l]) ++r;
    vector<Fp> nf;
    for (int i = 0; i < int(size(f)); ++i)
      for (int j = 0; j <= n * n; ++j) {
        if (c[l][r - l][j] == 0) continue;
        if (i + j >= int(size(nf))) nf.resize(i + j + 1);
        nf[i + j] += f[i] * c[l][r - l][j];
      }
    f = move(nf);
    l = r;
  }
  cout << (k < int(size(f)) ? f[k].val() : 0) << '\n';
}
0