結果

問題 No.269 見栄っ張りの募金活動
ユーザー ありあり
提出日時 2023-02-01 10:25:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 2,011 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 77,344 KB
実行使用メモリ 20,788 KB
最終ジャッジ日時 2023-09-13 23:15:13
合計ジャッジ時間 2,155 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
20,584 KB
testcase_01 AC 7 ms
20,504 KB
testcase_02 AC 7 ms
20,612 KB
testcase_03 AC 7 ms
20,500 KB
testcase_04 AC 10 ms
20,768 KB
testcase_05 AC 7 ms
20,656 KB
testcase_06 AC 8 ms
20,568 KB
testcase_07 AC 12 ms
20,788 KB
testcase_08 AC 7 ms
20,544 KB
testcase_09 AC 8 ms
20,528 KB
testcase_10 AC 7 ms
20,616 KB
testcase_11 AC 8 ms
20,496 KB
testcase_12 AC 7 ms
20,632 KB
testcase_13 AC 8 ms
20,500 KB
testcase_14 AC 7 ms
20,576 KB
testcase_15 AC 9 ms
20,548 KB
testcase_16 AC 7 ms
20,684 KB
testcase_17 AC 8 ms
20,572 KB
testcase_18 AC 9 ms
20,488 KB
testcase_19 AC 8 ms
20,608 KB
testcase_20 AC 8 ms
20,560 KB
testcase_21 AC 8 ms
20,596 KB
testcase_22 AC 8 ms
20,532 KB
testcase_23 AC 7 ms
20,752 KB
testcase_24 AC 7 ms
20,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
using namespace std;

const int mod = 1000000007;
struct mint {
  typedef long long ll;
  ll x;
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

        dp[i][j] = dp[i][j-1];
      }
    }
  }
  cout << dp[s][n] << endl;
}
0