結果
問題 | No.1238 選抜クラス |
ユーザー |
![]() |
提出日時 | 2020-09-25 21:49:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 295 ms / 2,000 ms |
コード長 | 3,214 bytes |
コンパイル時間 | 865 ms |
コンパイル使用メモリ | 79,228 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-06-28 06:23:25 |
合計ジャッジ時間 | 6,738 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <iostream> #include <cstdint> #include <cassert> template<std::int_fast32_t Modulus> struct modint { using value_type = std::int_fast32_t; static constexpr std::int_fast32_t mod = Modulus; static_assert(mod > 1, "Modulus must be greater than 1"); private : value_type x; template<class Tp> static constexpr value_type normalize (Tp value) noexcept { if (value < 0) { value = (-value) % mod; return (value ? value : mod - value); } return (value % mod); } public : explicit constexpr modint () noexcept : x(0) { } template<class Tp> constexpr modint (Tp value) noexcept : x(normalize(value)) { } constexpr modint operator+ () const noexcept { return modint(*this); } constexpr modint operator- () noexcept { if (x != 0) x = mod - x; return modint(*this); } constexpr modint &operator+= (const modint &p) noexcept { if ((x += p.x) >= mod) x -= mod; return (*this); } constexpr modint &operator-= (const modint &p) noexcept { if ((x += mod - p.x) >= mod) x -= mod; return (*this); } constexpr modint &operator*= (const modint &p) noexcept { x = (int)(1LL * x * p.x % mod); return (*this); } constexpr modint &operator/= (const modint &p) noexcept { return ((*this) *= p.inverse()); } constexpr modint operator+ (const modint &p) const noexcept { return (modint(*this) += p); } constexpr modint operator- (const modint &p) const noexcept { return (modint(*this) -= p); } constexpr modint operator* (const modint &p) const noexcept { return (modint(*this) *= p); } constexpr modint operator/ (const modint &p) const noexcept { return (modint(*this) /= p); } constexpr bool operator== (const modint &p) const noexcept { return (x == p.x); } constexpr bool operator!= (const modint &p) const noexcept { return (x != p.x); } template<class Tp> constexpr modint pow (Tp exp) const noexcept { modint value(1), buff(x); while (exp) { if (exp & 1) value *= buff; buff *= buff; exp >>= 1; } return value; } constexpr modint inverse () const noexcept { return pow(mod - 2); } friend std::ostream &operator<< (std::ostream &os, const modint &p) { return (os << p.x); } friend std::istream &operator>> (std::istream &is, modint &p) { long long v; is >> v; p = modint(v); return (is); } }; #include <iostream> #include <cstddef> #include <vector> using usize = std::size_t; using i32 = std::int_fast32_t; template<class T> using matrix = std::vector<std::vector<T>>; constexpr std::int_fast32_t MOD = 1000000007; constexpr usize MAX = 10010; int main() { usize n, k; std::cin >> n >> k; std::vector<usize> a(n); for (usize i = 0; i < n; i++) { std::cin >> a[i]; } matrix<modint<MOD>> dp(n + 1, std::vector<modint<MOD>>(MAX, 0)); matrix<modint<MOD>> next(n + 1, std::vector<modint<MOD>>(MAX, 0)); dp[0][0] = next[0][0] = 1; for (usize i = 0; i < n; i++) { for (usize j = 0; j < n; j++) { for (usize k = 0; k + a[i] < MAX; k++) { next[j + 1][k + a[i]] += dp[j][k]; } } dp = next; } modint<MOD> ans = 0; for (usize i = 1; i <= n; i++) { for (usize j = i * k; j < MAX; j++) { ans += dp[i][j]; } } std::cout << ans << '\n'; return 0; }