結果

問題 No.1238 選抜クラス
ユーザー kya_skikya_ski
提出日時 2020-09-25 21:49:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 3,214 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 77,040 KB
実行使用メモリ 19,008 KB
最終ジャッジ日時 2023-09-10 15:13:25
合計ジャッジ時間 5,877 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 4 ms
4,744 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,908 KB
testcase_09 AC 7 ms
5,472 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 6 ms
5,424 KB
testcase_12 AC 4 ms
4,848 KB
testcase_13 AC 4 ms
5,168 KB
testcase_14 AC 4 ms
4,624 KB
testcase_15 AC 7 ms
5,660 KB
testcase_16 AC 7 ms
5,660 KB
testcase_17 AC 211 ms
18,880 KB
testcase_18 AC 192 ms
18,412 KB
testcase_19 AC 203 ms
18,732 KB
testcase_20 AC 190 ms
18,144 KB
testcase_21 AC 178 ms
17,676 KB
testcase_22 AC 209 ms
18,840 KB
testcase_23 AC 208 ms
18,884 KB
testcase_24 AC 209 ms
19,008 KB
testcase_25 AC 209 ms
18,896 KB
testcase_26 AC 212 ms
18,888 KB
testcase_27 AC 214 ms
18,940 KB
testcase_28 AC 212 ms
18,884 KB
testcase_29 AC 206 ms
18,880 KB
testcase_30 AC 22 ms
8,020 KB
testcase_31 AC 67 ms
11,868 KB
testcase_32 AC 123 ms
15,508 KB
testcase_33 AC 3 ms
4,384 KB
testcase_34 AC 152 ms
16,468 KB
testcase_35 AC 33 ms
9,080 KB
testcase_36 AC 9 ms
5,908 KB
testcase_37 AC 25 ms
8,288 KB
testcase_38 AC 189 ms
18,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0