結果

問題 No.1621 Sequence Inversions
ユーザー SSRSSSRS
提出日時 2021-07-22 22:10:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 326 ms / 3,000 ms
コード長 1,063 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 182,288 KB
実行使用メモリ 107,784 KB
最終ジャッジ日時 2023-09-24 17:13:21
合計ジャッジ時間 5,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 5 ms
7,312 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,696 KB
testcase_08 AC 197 ms
32,680 KB
testcase_09 AC 129 ms
55,744 KB
testcase_10 AC 183 ms
107,784 KB
testcase_11 AC 223 ms
35,648 KB
testcase_12 AC 326 ms
41,696 KB
testcase_13 AC 311 ms
25,560 KB
testcase_14 AC 33 ms
4,628 KB
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 98 ms
5,620 KB
testcase_17 AC 228 ms
7,472 KB
testcase_18 AC 102 ms
5,432 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 43 ms
4,520 KB
testcase_21 AC 238 ms
8,200 KB
testcase_22 AC 61 ms
4,380 KB
testcase_23 AC 256 ms
9,484 KB
testcase_24 AC 2 ms
4,380 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 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[A[i]]++;
  }
  vector<long long> dp(K + 1, 0);
  dp[0] = 1;
  int S = 0;
  for (auto P : mp){
    int cnt = P.second;
    vector<vector<vector<long long>>> dp2(S + 2, vector<vector<long long>>(cnt + 1, vector<long long>(K + 1, 0)));
    dp2[0][0] = dp;
    for (int i = 0; i <= S; i++){
      for (int j = 0; j <= cnt; j++){
        for (int k = 0; k <= K; k++){
          if (dp2[i][j][k] != 0){
            for (int l = 0; l <= cnt - j; l++){
              if ((S - i) * l <= K - k){
                int k2 = k + (S - i) * l;
                dp2[i + 1][j + l][k2] += dp2[i][j][k];
                dp2[i + 1][j + l][k2] %= MOD;
              }
            }
          }
        }
      }
    }
    for (int i = 0; i <= K; i++){
      dp[i] = dp2[S + 1][cnt][i];
    }
    S += cnt;
  }
  cout << dp[K] << endl;
}
0