結果

問題 No.1238 選抜クラス
ユーザー keijakkeijak
提出日時 2020-09-25 21:50:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 6,633 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 212,792 KB
実行使用メモリ 406,016 KB
最終ジャッジ日時 2024-06-28 06:25:04
合計ジャッジ時間 8,687 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 441 ms
402,048 KB
testcase_18 AC 387 ms
371,200 KB
testcase_19 AC 403 ms
382,592 KB
testcase_20 AC 357 ms
342,272 KB
testcase_21 AC 328 ms
317,696 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,948 KB
testcase_24 AC 423 ms
406,016 KB
testcase_25 AC 421 ms
405,888 KB
testcase_26 AC 415 ms
401,920 KB
testcase_27 AC 423 ms
405,888 KB
testcase_28 AC 423 ms
406,016 KB
testcase_29 AC 394 ms
378,880 KB
testcase_30 AC 15 ms
14,848 KB
testcase_31 AC 74 ms
71,296 KB
testcase_32 AC 202 ms
188,800 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 265 ms
251,904 KB
testcase_35 AC 26 ms
26,496 KB
testcase_36 AC 5 ms
6,940 KB
testcase_37 AC 17 ms
17,152 KB
testcase_38 AC 363 ms
349,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = std::int64_t;
using u64 = std::uint64_t;
#define REP(i, n) for (int i = 0; i < (i64)(n); ++i)
#define ALL(x) std::begin(x), std::end(x)
#define SIZE(a) (int)((a).size())

template <class T>
inline bool chmax(T &a, T b) {
  return a < b and ((a = std::move(b)), true);
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b and ((a = std::move(b)), true);
}

template <typename T>
using V = std::vector<T>;
template <typename T>
std::vector<T> make_vec(size_t n, T a) {
  return std::vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return std::vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
template <typename Container>
std::ostream &pprint(const Container &a, std::string_view sep = " ",
                     std::string_view ends = "\n", std::ostream *os = nullptr) {
  if (os == nullptr) os = &std::cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
                                  decltype(std::end(std::declval<T>()))>>
    : std::true_type {};

template <typename T,
          typename = std::enable_if_t<is_iterable<T>::value &&
                                      !std::is_same<T, std::string>::value>>
std::ostream &operator<<(std::ostream &os, const T &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void pdebug(const T &value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void pdebug(const T &value, const Ts &... args) {
  pdebug(value);
  std::cerr << ", ";
  pdebug(args...);
}
#define DEBUG(...)                                   \
  do {                                               \
    std::cerr << " \033[33m (L" << __LINE__ << ") "; \
    std::cerr << #__VA_ARGS__ << ":\033[0m ";        \
    pdebug(__VA_ARGS__);                             \
    std::cerr << std::endl;                          \
  } while (0)
#else
#define pdebug(...)
#define DEBUG(...)
#endif

// Extended Euclidean algorithm
// Returns gcd(a,b).
// x and y are set to satisfy `a*x + b*y == gcd(a,b)`
long long ext_gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = ext_gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

template <unsigned int M>
struct ModInt {
  constexpr ModInt(long long val = 0) : _v(0) {
    if (val < 0) {
      long long k = (abs(val) + M - 1) / M;
      val += k * M;
    }
    assert(val >= 0);
    _v = val % M;
  }

  static constexpr int mod() { return M; }
  static constexpr unsigned int umod() { return M; }
  inline unsigned int val() const { return _v; }

  ModInt &operator++() {
    _v++;
    if (_v == umod()) _v = 0;
    return *this;
  }
  ModInt &operator--() {
    if (_v == 0) _v = umod();
    _v--;
    return *this;
  }
  ModInt operator++(int) {
    auto result = *this;
    ++*this;
    return result;
  }
  ModInt operator--(int) {
    auto result = *this;
    --*this;
    return result;
  }

  constexpr ModInt operator-() const { return ModInt(-_v); }
  constexpr ModInt &operator+=(const ModInt &a) {
    if ((_v += a._v) >= M) _v -= M;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &a) {
    if ((_v += M - a._v) >= M) _v -= M;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &a) {
    _v = ((unsigned long long)(_v)*a._v) % M;
    return *this;
  }
  constexpr ModInt pow(unsigned long long t) const {
    assert(t >= 0);
    ModInt base = *this;
    ModInt res = 1;
    while (t) {
      if (t & 1) res *= base;
      base *= base;
      t >>= 1;
    }
    return res;
  }

  // Inverse by Extended Euclidean algorithm.
  // M doesn't need to be prime, but x and M must be coprime.
  constexpr ModInt inv() const {
    assert(_v != 0);
    long long x, y;
    long long g = ext_gcd(_v, M, x, y);
    assert(g == 1LL);  // gcd(_v, M) must be 1.
    return x;
  }
  constexpr ModInt &operator/=(const ModInt &a) { return *this *= a.inv(); }

  friend constexpr ModInt operator+(const ModInt &a, const ModInt &b) {
    return ModInt(a) += b;
  }
  friend constexpr ModInt operator-(const ModInt &a, const ModInt &b) {
    return ModInt(a) -= b;
  }
  friend constexpr ModInt operator*(const ModInt &a, const ModInt &b) {
    return ModInt(a) *= b;
  }
  friend constexpr ModInt operator/(const ModInt &a, const ModInt &b) {
    return ModInt(a) /= b;
  }
  friend constexpr bool operator==(const ModInt &a, const ModInt &b) {
    return a._v == b._v;
  }
  friend constexpr bool operator!=(const ModInt &a, const ModInt &b) {
    return a._v != b._v;
  }
  friend std::istream &operator>>(std::istream &is, ModInt &a) {
    return is >> a._v;
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) {
    return os << a._v;
  }

 private:
  unsigned int _v;
};
const unsigned int MOD = 1'000'000'007;
using Mint = ModInt<MOD>;

// Runtime MOD:
//   unsigned int MOD = 1'000'000'007;  // modifiable.
//   template <unsigned int& M> struct ModInt { ... };
//   using Mint = ModInt<MOD>;

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  V<int> A(N);
  cin >> A;
  // sort(A.rbegin(), A.rend());
  const int M = (*max_element(ALL(A))) * N;
  auto dp = make_vec(N + 1, N + 1, M + 1, Mint(0));
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    auto ai = A[i - 1];
    dp[i][0][0] = 1;
    for (int j = 1; j <= i; ++j) {
      dp[i][j] = dp[i - 1][j];
      for (int x = 0; x + ai <= M; ++x) {
        dp[i][j][x + ai] += dp[i - 1][j - 1][x];
      }
    }
  }
  //   if (N == 2 and K == 2) {
  //     for (int j = 0; j <= N; ++j) {
  //       for (int x = 0; x <= M; ++x) {
  //         cerr << dp[N][j][x] << ' ';
  //       }
  //       cerr << endl;
  //     }
  //   }
  Mint ans = 0;
  REP(j, N + 1) {
    for (int x = j * K; x <= M; ++x) {
      ans += dp[N][j][x];
      //   if (dp[N][j][x].val() > 0) {
      //     DEBUG(j, x, dp[N][j][x], ans.val());
      //   }
    }
  }
  cout << ans - 1 << endl;
}
0