結果

問題 No.269 見栄っ張りの募金活動
ユーザー ynayna
提出日時 2020-02-20 08:58:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 2,719 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 164,500 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-17 06:18:17
合計ジャッジ時間 2,562 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,620 KB
testcase_01 AC 5 ms
11,336 KB
testcase_02 AC 5 ms
11,472 KB
testcase_03 AC 5 ms
11,432 KB
testcase_04 AC 15 ms
11,420 KB
testcase_05 AC 5 ms
11,520 KB
testcase_06 AC 4 ms
11,584 KB
testcase_07 AC 32 ms
11,312 KB
testcase_08 AC 4 ms
11,344 KB
testcase_09 AC 4 ms
11,520 KB
testcase_10 AC 5 ms
11,648 KB
testcase_11 AC 6 ms
11,332 KB
testcase_12 AC 5 ms
11,392 KB
testcase_13 AC 7 ms
11,520 KB
testcase_14 AC 5 ms
11,376 KB
testcase_15 AC 7 ms
11,488 KB
testcase_16 AC 4 ms
11,548 KB
testcase_17 AC 4 ms
11,392 KB
testcase_18 AC 12 ms
11,520 KB
testcase_19 AC 7 ms
11,392 KB
testcase_20 AC 5 ms
11,508 KB
testcase_21 AC 6 ms
11,428 KB
testcase_22 AC 6 ms
11,540 KB
testcase_23 AC 4 ms
11,392 KB
testcase_24 AC 5 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// fatorial.cpp depend on this.
#ifndef MOD_INT
#define MOD_INT
template<int mod>
struct ModInt{
	private:
		int x;

	public:
		ModInt() : x(0){}
		ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}
	
		ModInt &operator+=(const ModInt &p){
			if((x += p.x) >= mod) x -= mod;
			return *this;
		}
		ModInt &operator-=(const ModInt &p){
			if((x += mod - p.x) >= mod) x -= mod;
			return *this;
		}
		ModInt &operator*=(const ModInt &p){
			x = (int) (1LL * x * p.x % mod);
			return *this;
		}
		ModInt &operator/=(const ModInt &p){
			*this *= p.inverse();
			return *this;
		}
	
		ModInt operator-() const {return ModInt(-x);}
		ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
		ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
		ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
		ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}
		bool operator==(const ModInt &p) const {return x == p.x;}
		bool operator!=(const ModInt &p) const {return x != p.x;}
		bool operator<(const ModInt &p) const {return x < p.x;}
		void operator=(const int &p){x = p >= 0 ? p % mod : (mod - (-p) % mod) % mod;}
	
		template<typename T>
		operator T() const {return (T)x;}
	
		ModInt inverse() const {
			int a = x, b = mod, u = 1, v = 0, t;
			while(b > 0) {
				t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return ModInt(u);
		}
	
		ModInt pow(int64_t n) const {
			ModInt ret(1), mul(x);
			while(n > 0) {
				if(n & 1) ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}
	
		friend ostream &operator<<(ostream &os, const ModInt &p){
			return os << p.x;
		}
	
		friend istream &operator>>(istream &is, ModInt &a){
			int64_t t;
			is >> t;
			a = ModInt< mod >(t);
			return (is);
		}
	
		static int get_mod(){return mod;}
};

using mint = ModInt<MOD>;
#endif

mint dp[20001][101];

int N, S, K;

int main(void){
    cin >> N >> S >> K;
    int M = S - N * (N-1) * K / 2;
    for(int i = 0; i <= M; i++){
        for(int j = 0; j <= N; j++){
            dp[i][j] = 0;
        }
    }

    if(M < 0){
        cout << "0\n";
        return 0;
    }

    dp[0][0] = 1;
    
    for(int j = 0; j <= N; j++){
        for(int i = 0; i <= M; i++){
            if(j-1 >= 0) dp[i][j] += dp[i][j-1];
            if(i-j >= 0 and i != 0) dp[i][j] += dp[i-j][j];
            // printf("dp(%d, %d) = ", i, j);
            // cout << dp[i][j] << '\n';
        }
    }

    cout << dp[M][N] << '\n';

    return 0;
}
0