結果

問題 No.269 見栄っ張りの募金活動
ユーザー 303Yuyu303Yuyu
提出日時 2021-01-18 16:59:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 3,601 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 108,092 KB
実行使用メモリ 21,168 KB
最終ジャッジ日時 2023-08-21 00:20:22
合計ジャッジ時間 2,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 27 ms
10,928 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 72 ms
21,168 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 8 ms
6,180 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 10 ms
5,912 KB
testcase_14 AC 7 ms
6,792 KB
testcase_15 AC 9 ms
5,904 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 24 ms
9,328 KB
testcase_19 AC 9 ms
5,216 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 6 ms
5,956 KB
testcase_22 AC 6 ms
4,596 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 5 ms
4,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <functional>
#include <cassert>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}
template <class T> ostream& operator<<(ostream& s, const vector<T>& a) { for(auto i : a) s << i << ' '; return s; }

constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
    static const long long mod = 1000000007;
    long long x;
    mint(long long 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;}

    friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; }
    friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; }
    friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; }
    friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; }

    mint pow(long long 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();}
    friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; }
};

struct combi {
    const static long long mod = mint::mod;
    int n;
    vector<mint> fac, finv, inv;
    
    combi(int _n) : n(_n + 1), fac(n, 1), finv(n, 1), inv(n, 1) {
        for (int i = 2; i < n; ++i) {
            fac[i] = fac[i - 1] * i;
            inv[i] =- inv[mod % i] * (mod / i);
            finv[i] = finv[i - 1] * inv[i];
        }
    };

    mint get(int n, int k) {
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        mint ret = fac[n] * finv[k] * finv[n - k];
        return ret;
    }
};

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

    vector<vb> memob(s+1, vb(n+1, false));
    using vm = vector<mint>;
    vector<vm> memom(s+1, vm(n+1));
    function<mint(int, int)> rec = [&](int a, int b) {
        if(a < 0 || b == 0) return mint(0);
        else if(a == 0 || b == 1) return mint(1);
        else if(memob[a][b]) return memom[a][b];
        memom[a][b] += rec(a, b-1) + rec(a-b, b);
        memob[a][b] = true;
        return memom[a][b];
    };
    cout << rec(s, n) << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}
0