結果

問題 No.1861 Required Number
ユーザー niuezniuez
提出日時 2022-03-04 22:00:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 235 ms / 2,500 ms
コード長 2,443 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 205,400 KB
実行使用メモリ 160,160 KB
最終ジャッジ日時 2023-09-26 03:31:30
合計ジャッジ時間 10,779 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,380 KB
testcase_03 AC 235 ms
160,160 KB
testcase_04 AC 235 ms
160,148 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 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 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,468 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 68 ms
55,684 KB
testcase_25 AC 174 ms
138,720 KB
testcase_26 AC 31 ms
25,372 KB
testcase_27 AC 64 ms
50,440 KB
testcase_28 AC 75 ms
58,412 KB
testcase_29 AC 45 ms
34,000 KB
testcase_30 AC 12 ms
9,188 KB
testcase_31 AC 176 ms
140,664 KB
testcase_32 AC 17 ms
13,628 KB
testcase_33 AC 120 ms
95,984 KB
testcase_34 AC 143 ms
113,936 KB
testcase_35 AC 145 ms
115,520 KB
testcase_36 AC 48 ms
35,792 KB
testcase_37 AC 72 ms
55,500 KB
testcase_38 AC 150 ms
117,988 KB
testcase_39 AC 83 ms
65,372 KB
testcase_40 AC 176 ms
139,904 KB
testcase_41 AC 165 ms
132,112 KB
testcase_42 AC 135 ms
107,384 KB
testcase_43 AC 72 ms
57,344 KB
testcase_44 AC 2 ms
4,380 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;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];

  const i64 MOD = 998244353;

  auto dp = ndvec(N + 1, K + 1, 0ll);
  dp[0][0] = 1;
  rep(i,0,N) {
    rep(k,0,K + 1) {
      (dp[i + 1][k] += dp[i][k]) %= MOD;
      if(k - A[i] >= 0) {
        (dp[i + 1][k] += dp[i][k - A[i]]) %= MOD;
      }
    }
  }
  auto rdp = ndvec(N + 1, K + 1, 0ll);
  rdp[N][0] = 1;
  for(int i = N; i --> 0;) {
    rep(k,0,K + 1) {
      (rdp[i][k] += rdp[i + 1][k]) %= MOD;
      if(k - A[i] >= 0) {
        (rdp[i][k] += rdp[i + 1][k - A[i]]) %= MOD;
      }
    }
  }
  i64 ans = 0;
  if(dp[N][K] == 0) {
    cout << -1 << endl;
    return 0;
  }
  rep(i,0,N) {
    i64 cnt = 0;
    rep(k,0,K - A[i] + 1) {
      (cnt += dp[i][k] * rdp[i + 1][K - k - A[i]]) %= MOD;
    }
    if(cnt == dp[N][K]) {
      ans++;
    }
  }
  cout << ans << endl;
}
0