結果

問題 No.1621 Sequence Inversions
ユーザー SSRSSSRS
提出日時 2021-07-22 22:03:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,211 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 180,808 KB
実行使用メモリ 107,772 KB
最終ジャッジ日時 2023-09-24 17:03:17
合計ジャッジ時間 8,397 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 7 ms
7,332 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,836 KB
testcase_08 WA -
testcase_09 AC 107 ms
56,040 KB
testcase_10 AC 184 ms
107,772 KB
testcase_11 WA -
testcase_12 AC 341 ms
41,672 KB
testcase_13 AC 550 ms
25,548 KB
testcase_14 AC 26 ms
4,512 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 240 ms
5,428 KB
testcase_17 AC 725 ms
7,384 KB
testcase_18 AC 230 ms
5,456 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 112 ms
4,476 KB
testcase_21 AC 890 ms
8,168 KB
testcase_22 AC 76 ms
4,504 KB
testcase_23 AC 1,236 ms
9,548 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 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][0] = 1;
    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;
              }
            }
          }
        }
      }
    }
    vector<long long> dp3(K + 1, 0);
    for (int i = 0; i <= K; i++){
      for (int j = 0; j <= K - i; j++){
        dp3[i + j] += dp[i] * dp2[S + 1][cnt][j];
        dp3[i + j] %= MOD;
      }
    }
    swap(dp, dp3);
    S += cnt;
  }
  cout << dp[K] << endl;
}
0