結果
| 問題 |
No.269 見栄っ張りの募金活動
|
| コンテスト | |
| ユーザー |
peroon
|
| 提出日時 | 2019-07-31 07:09:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 5,000 ms |
| コード長 | 1,778 bytes |
| コンパイル時間 | 3,715 ms |
| コンパイル使用メモリ | 174,484 KB |
| 実行使用メモリ | 20,224 KB |
| 最終ジャッジ日時 | 2024-07-05 06:22:37 |
| 合計ジャッジ時間 | 2,838 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
// 分割数 n個のものをm個以下に分割する
// 蟻本v2 p66
struct PartitionFunction{
vector<vector<ll>> dp; //dp[M][N]
ll N = -1;
ll M = -1;
void init(ll n, ll m){
N = n;
M = m;
// 大きめに確保
dp.resize(M+5);
REP(i, M+5){
dp[i].resize(N+5, 0);
}
prepare();
}
void prepare(){
dp[0][0] = 1;
FOR(i, 1, M+1){
FOR(j, 0, N+1){
if(j-i>=0){
dp[i][j] = (dp[i-1][j] + dp[i][j-i]) % mod;
}else{
dp[i][j] = dp[i-1][j];
}
}
}
}
ll f(ll n, ll m){
return dp[m][n];
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
ll N, S, K;
cin >> N >> S >> K;
// K円を先に徴収する
FOR(i, 0, N){
S -= K*i;
}
if(S<0){
p(0);
return 0;
}
// 残りを分割数で分けて、昇順に割り振るとする
auto partition = PartitionFunction();
partition.init(20000, 100);
ll ans = partition.f(S, N);
p(ans);
return 0;
}
peroon