結果

問題 No.269 見栄っ張りの募金活動
ユーザー 土井洋平土井洋平
提出日時 2020-06-04 18:59:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 907 bytes
コンパイル時間 1,419 ms
コンパイル使用メモリ 165,200 KB
実行使用メモリ 19,120 KB
最終ジャッジ日時 2023-08-19 23:20:55
合計ジャッジ時間 2,651 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

ll const mod = 1000000007;

int main(){
    /*
    a1+K≤a2,a1+2K≤a3,⋯,a1+NK≤an
    ここでbi = ai - ikとすると, b1<= b2 <= b3...となる。
    s= a1 + a2 .. anの条件式に代入すると
    b1 + b2 .. bn = s - (k + 2k + ...nk)= s - n(n-1)k/2 となる。あとは分割法
    */

    int n, s, k;
    cin >> n >> s >> k;
    s -= n*(n-1)*k/2;
    if(s<0){
        cout << 0 << endl;
        return 0;
    }

    //dp[i][j] jのi分割
    ll dp[n+1][s+1] = {};
    dp[0][0] = 1;
    for(int i=1;i<=n;i++)rep(j,s+1){
        if(j-i>=0){
            dp[i][j] = ((dp[i][j-i] + dp[i-1][j]) % mod);

        }
        else{//iの方が大きいと分割できない
            dp[i][j] = dp[i-1][j] % mod;
        }
    }
    
    cout << dp[n][s] << endl;
}
0