結果

問題 No.269 見栄っ張りの募金活動
ユーザー Yang33Yang33
提出日時 2018-09-23 17:22:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 2,617 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 169,812 KB
実行使用メモリ 19,372 KB
最終ジャッジ日時 2023-09-23 01:34:53
合計ジャッジ時間 2,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 8 ms
9,004 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 18 ms
19,372 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,732 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,924 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,796 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 7 ms
8,564 KB
testcase_19 AC 4 ms
4,560 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/09/19  Problem: yukicoder 269  / Link: http://yukicoder.me/problems/no/269  ----- */
/* ------問題------

学校で募金活動をすることになり、N人のクラスでS円を集め寄付することにした。
生徒は出席番号順に寄付金額(0以上の整数)を決めていく。

このクラスの生徒は皆見栄っ張りであり、出席番号順が1つ前の生徒に比べてK円以上高い金額を寄付しないと気が済まず不満になるようだ。
(最初に金額を決める生徒は比べる相手がいないので何円寄付しても良い。0円でも構わない)

不満な生徒が現れることなく、クラスの合計寄付金額がちょうどS円となるような各生徒の寄付金額の組み合わせは何通りあるか。
組み合わせ数を10^9+7で割った余りを答えよ。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */




LL slow(LL N, LL S, LL K) {
	VVL dp(N + 1, VL(S + 1, 0));
	dp[0][0] = 1;

	FOR(i, 0, N) {
		FOR(k, 0, S + 1) {
			FOR(s, 0, S + 1 - (N - i)*k) {
				(dp[i + 1][s + (N - i)*k] += dp[i][s]) %= MOD;
			}
		}
	}
	return dp[N][S];
}

// N人でS円
LL fast(LL N, LL S) {
	VVL dp(N + 1, VL(S + 1, 0));
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= S; j++) {
			if (j - i >= 0) {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % MOD;
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	return dp[N][S];
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, S, K; cin >> N >> S >> K;

	S -= K * N* (N - 1) / 2;
	LL ans = 0;
	if (S >= 0) {
//		ans = slow(N,S,K);
		ans = fast(N,S);
	}

	cout << ans << "\n";

	return 0;
}
0