結果

問題 No.269 見栄っ張りの募金活動
ユーザー ose20ose20
提出日時 2019-12-20 17:56:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 2,428 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 170,352 KB
実行使用メモリ 20,244 KB
最終ジャッジ日時 2023-09-23 00:04:34
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 12 ms
9,856 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 29 ms
20,244 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 5 ms
5,492 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 5 ms
5,476 KB
testcase_14 AC 4 ms
4,888 KB
testcase_15 AC 6 ms
5,368 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 12 ms
9,188 KB
testcase_19 AC 5 ms
5,232 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 4 ms
4,672 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

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

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

    vector<vector<ll>> dp(S+5, vector<ll>(n+5, 0));
    dp[0][0] = 1;    
    rep(i, S+1) repr(j, 1, n+1) {
        dp[i][j] = dp[i][j-1];
        if (i-j>=0) dp[i][j] += dp[i-j][j];
        chmod(dp[i][j]);
    }
    cout << dp[S][n] << endl;
    
    return 0;
}
0