結果
| 問題 |
No.269 見栄っ張りの募金活動
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-13 00:38:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 3,025 bytes |
| コンパイル時間 | 6,068 ms |
| コンパイル使用メモリ | 254,136 KB |
| 最終ジャッジ日時 | 2025-02-14 02:13:04 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#ifdef LOCAL
#include <debug.h>
#define dbg(...) debug::dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) void(0)
#endif
using namespace std;
// #define int long long
#define rep(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i < i##_end__; i++)
#define rep_r(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i >= i##_end__; i--)
#define fore(i, a) for(auto& i: a)
#define all(x) std::begin(x), std::end(x)
using ll = long long; // __int128;
using ull = unsigned long long;
template<class C> int siz(const C& c) { return static_cast<int>(c.size()); }
template<class T, size_t N> constexpr int siz(const T (&)[N]) { return static_cast<int>(N); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> constexpr T pow2(T x){ return x * x; }
template<class T, class S> constexpr T divceil(T x, S div){ return (x + div - 1) / div; }
constexpr long long INF = 1LL << 60; // 1.15e18
// constexpr int MOD = (int)1e9 + 7;
// 分割数 P(n, k) - 自然数 n を k 個の 0 以上の整数の和で表す方法の数 - 漸化式計算 O(nk)
// ※「k 個の 1 以上の整数への分割」は P(n-k, k) 通り
template<class T> struct Partition {
vector<vector<T>> P;
constexpr Partition(int N, int K) noexcept : P(N + 1, vector<T>(K + 1, 0)) {
for (int k = 0; k <= K; ++k) P[0][k] = 1;
for (int n = 1; n <= N; ++n) {
for (int k = 1; k <= K; ++k) {
// 漸化式
// P(n,k)=P(n,k−1)+P(n−k,k)
// n を k 個の 0 以上の整数の和として表す方法のうち、
// 分解に 0 を含むものについては、そのうちのどれかの 0 を取り除いてしまうことで、n を k−1 個の 0 以上の整数の和として表す方法に帰着される。よって、P(n,k−1) 通り。
// 分解に 0 を含まない場合は、k 個の整数がすべて 1 以上なので、それぞれ 1 を引くことで n−k を k 個の 0 以上の整数の和として表す方法に帰着される。よって、P(n−k,k) 通り。
P[n][k] = P[n][k - 1] + (n - k >= 0 ? P[n - k][k] : 0);
}
}
}
constexpr Partition(int N) noexcept : Partition(N, N) {}
constexpr T get(int n, int k) {
if (n < 0 || k < 0) return 0;
return P[n][k];
}
};
void _main() {
int N, S, K;
cin >> N >> S >> K;
rep(i, 0, N) S -= K * i;
if(S < 0){
cout << 0 << endl;
return;
}
using mint = modint1000000007;
auto par = Partition<mint>(S, N);
cout << par.get(S, N).val() << endl;
}
signed main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
cout << fixed << setprecision(15); cerr << fixed << setprecision(15);
_main();
}