結果

問題 No.1861 Required Number
ユーザー SSRSSSRS
提出日時 2022-03-04 21:27:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 206,400 KB
実行使用メモリ 160,140 KB
最終ジャッジ日時 2023-09-26 03:11:13
合計ジャッジ時間 10,793 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 3 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,376 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

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];
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(K * 2 + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++){
    for (int j = 0; j <= K * 2; j++){
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
      if (j + A[i] <= K * 2){
        dp[i + 1][j + A[i]] += dp[i][j];
        dp[i + 1][j + A[i]] %= MOD;
      }
    }
  }
  if (dp[N][K] == 0){
    cout << -1 << endl;
  } else {
    int ans = 0;
    for (int i = 0; i < N; i++){
      vector<long long> tmp = dp[N];
      for (int j = 0; j <= K * 2 - A[i]; j++){
        tmp[j + A[i]] -= tmp[j];
        tmp[j + A[i]] += MOD;
        tmp[j + A[i]] %= MOD;
      }
      if (tmp[K] == 0){
        ans++;
      }
    }
    cout << ans << endl;
  }
}
0