結果

問題 No.269 見栄っ張りの募金活動
ユーザー zelnyokzelnyok
提出日時 2019-08-25 17:27:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,577 ms / 5,000 ms
コード長 2,439 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 102,928 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-24 12:23:16
合計ジャッジ時間 7,125 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 1,109 ms
8,960 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1,577 ms
19,584 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 507 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 217 ms
5,376 KB
testcase_14 AC 407 ms
5,376 KB
testcase_15 AC 319 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 331 ms
8,576 KB
testcase_19 AC 103 ms
5,376 KB
testcase_20 AC 80 ms
5,376 KB
testcase_21 AC 353 ms
5,376 KB
testcase_22 AC 75 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 209 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()

#define dump2(v) for(auto i:v) { for(auto j:i) std::cout << j << ' '; std::cout << "\n"; }

constexpr int MOD = 1e9+7;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this;}
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this;}
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this;}
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this;}
	mint& operator/=(const mint& a){ (*this) *= a.inv(); 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 operator/(const mint& a)const{ return mint(*this) /= a;}
	bool operator<(const mint& a)const{ return v < a.v;}
	bool operator==(const mint& a)const{ return v == a.v;}
	mint pow(int k)const{mint r(1),t(v);while(k){if(k&1)r*=t;t*=t;k>>=1;} return r;}
	mint inv()const{return pow(MOD-2);}
};
std::istream& operator>>(std::istream&i,mint&a){int t;i>>t;a=mint(t);return i;}
std::ostream& operator<<(std::ostream&o,const mint&a){o<<a.v;return o;}

signed main() {
    std::ios_base::sync_with_stdio(0); 
    std::cin.tie(0);

	int n,s,k;
	std::cin >> n >> s >> k;

	s -= k*(n-1)*n/2;
	if(s<0) {
		print(0);
		return 0;
	}

	std::vector<std::vector<mint> > dp(n+1,std::vector<mint>(s+1,0));
	dp[0][0] = 1;
	rep(i,n) {
		rep(j,s+1) {
			int c = 0;
			while(j+(n-i)*c<=s) {
				dp[i+1][j+(n-i)*c] += dp[i][j];
				c++;
			}
		}
	}
	print(dp[n][s]);
	return 0;
}
0