結果

問題 No.269 見栄っ張りの募金活動
ユーザー K UK U
提出日時 2023-06-13 00:36:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 2,964 bytes
コンパイル時間 5,759 ms
コンパイル使用メモリ 264,252 KB
実行使用メモリ 11,880 KB
最終ジャッジ日時 2023-09-02 17:31:15
合計ジャッジ時間 6,767 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 6 ms
6,792 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 14 ms
11,880 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 4 ms
4,412 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 4 ms
4,508 KB
testcase_14 AC 3 ms
4,368 KB
testcase_15 AC 3 ms
4,580 KB
testcase_16 AC 1 ms
4,368 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 6 ms
6,196 KB
testcase_19 AC 3 ms
4,372 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 4 ms
4,368 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 AC 3 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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