結果

問題 No.269 見栄っ張りの募金活動
ユーザー kokesakakokesaka
提出日時 2022-06-10 16:17:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,555 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 171,708 KB
実行使用メモリ 19,708 KB
最終ジャッジ日時 2023-10-21 04:41:43
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 10 ms
9,676 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 21 ms
19,708 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 4 ms
5,188 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 4 ms
5,616 KB
testcase_14 AC 3 ms
4,396 KB
testcase_15 AC 4 ms
5,576 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 9 ms
9,192 KB
testcase_19 AC 4 ms
5,336 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 4 ms
4,468 KB
testcase_22 AC 4 ms
4,952 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 4 ms
4,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main(){
    int n,s,k;
    cin >> n >> s >> k;
    s = s-k*n*(n-1)/2;
    if(s<0) {cout << 0 << endl; return 0;}
    vector<vector<mint>> dp(s+1,vector<mint>(n+1,0));
    dp[0][0]=1;
    rep(i,s+1)for(int j=1;j<n+1;++j){
    if(i-j>=0) dp[i][j]=dp[i][j-1]+dp[i-j][j];
    else       dp[i][j]=dp[i][j-1];
    }
    cout << dp[s][n].x << endl;
}
0