結果

問題 No.269 見栄っ張りの募金活動
ユーザー peroonperoon
提出日時 2019-07-31 07:09:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,778 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 171,984 KB
実行使用メモリ 20,064 KB
最終ジャッジ日時 2023-09-18 15:53:29
合計ジャッジ時間 3,224 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 18 ms
19,848 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 18 ms
20,052 KB
testcase_04 AC 18 ms
19,964 KB
testcase_05 AC 18 ms
19,864 KB
testcase_06 AC 18 ms
19,872 KB
testcase_07 AC 18 ms
20,056 KB
testcase_08 AC 18 ms
20,064 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 18 ms
19,864 KB
testcase_11 AC 18 ms
19,916 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 19 ms
19,848 KB
testcase_14 AC 19 ms
19,928 KB
testcase_15 AC 18 ms
19,848 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 19 ms
19,884 KB
testcase_19 AC 18 ms
19,888 KB
testcase_20 AC 18 ms
19,968 KB
testcase_21 AC 19 ms
19,844 KB
testcase_22 AC 19 ms
20,000 KB
testcase_23 AC 18 ms
19,952 KB
testcase_24 AC 18 ms
19,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// 分割数 n個のものをm個以下に分割する
// 蟻本v2 p66
struct PartitionFunction{
    vector<vector<ll>> dp; //dp[M][N]
    ll N = -1;
    ll M = -1;
    void init(ll n, ll m){
        N = n;
        M = m;
        // 大きめに確保
        dp.resize(M+5);
        REP(i, M+5){
            dp[i].resize(N+5, 0);
        }
        prepare();
    }
    void prepare(){
        dp[0][0] = 1;
        FOR(i, 1, M+1){
            FOR(j, 0, N+1){
                if(j-i>=0){
                    dp[i][j] = (dp[i-1][j] + dp[i][j-i]) % mod;
                }else{
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
    }
    ll f(ll n, ll m){
        return dp[m][n];
    }
};

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

    // input
    ll N, S, K;
    cin >> N >> S >> K;
    
    // K円を先に徴収する
    FOR(i, 0, N){
        S -= K*i;
    }
    if(S<0){
        p(0);
        return 0;
    }

    // 残りを分割数で分けて、昇順に割り振るとする
    auto partition = PartitionFunction();
    partition.init(20000, 100);
    ll ans = partition.f(S, N);
    p(ans);
    
    return 0;
}
0