結果
問題 | No.269 見栄っ張りの募金活動 |
ユーザー |
![]() |
提出日時 | 2020-05-30 22:59:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 5,000 ms |
コード長 | 3,185 bytes |
コンパイル時間 | 1,594 ms |
コンパイル使用メモリ | 125,476 KB |
最終ジャッジ日時 | 2025-01-10 19:42:55 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <iostream>#include <iomanip>#include <cmath>#include <string>#include <vector>#include <map>#include <unordered_map>#include <set>#include <unordered_set>#include <queue>#include <numeric>#include <random>#include <algorithm>#include <functional>#include <cassert>using namespace std;typedef long long ll;template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}const int INF = (1 << 30) - 1;const ll INFLL= (1LL << 61) - 1;const int MOD = 1000000007;#define ALL(a) (a).begin(),(a).end()#define rALL(a) (a).rbegin(),(a).rend()#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)template<int Modulo = MOD>struct Mint {ll val;constexpr Mint(ll v = 0) noexcept : val(v % Modulo) { if (val < 0) val += Modulo; }constexpr Mint& operator += (const Mint &r) noexcept {val += r.val;if (val >= Modulo) val -= Modulo;return *this;}constexpr Mint& operator -= (const Mint &r) noexcept {val -= r.val;if (val < 0) val += Modulo;return *this;}constexpr Mint& operator *= (const Mint &r) noexcept {val = val * r.val % Modulo;return *this;}constexpr Mint& operator /= (const Mint &r) noexcept {ll a = r.val, b = Modulo, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}val = val * u % Modulo;if (val < 0) val += Modulo;return *this;}constexpr Mint operator + (const Mint &r) const noexcept { return Mint(*this) += r; }constexpr Mint operator - (const Mint &r) const noexcept { return Mint(*this) -= r; }constexpr Mint operator * (const Mint &r) const noexcept { return Mint(*this) *= r; }constexpr Mint operator / (const Mint &r) const noexcept { return Mint(*this) /= r; }constexpr int getmod() { return Modulo; }constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }constexpr bool operator == (const Mint &r) const noexcept { return val == r.val; }constexpr bool operator != (const Mint &r) const noexcept { return val != r.val; }friend ostream &operator << (ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; }friend istream &operator >> (istream &is, Mint<Modulo> &x) noexcept {ll tmp; is >> tmp;x = Mint(tmp);return is;}constexpr Mint pow(ll n) noexcept {Mint res{ 1 }, tmp{ val };while (n > 0) {if (n & 1) res *= tmp;tmp *= tmp;n >>= 1;}return res;}};using mint = Mint<>;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);ll N,S,K;cin>>N>>S>>K;// i-1人目まで見て、後の人が最低同額払うとして総計j円払ったときの場合の数vector<vector<mint>>dp(N+1,vector<mint>(S+1));dp[0][0]=1;REP(i,N){REP(j,S+1){if(i>0)dp[i][j]=dp[i-1][j];if(j-i-1>=0){dp[i][j] += dp[i][j-i-1];}}}if(S-K*(N-1)*N/2>=0){cout<<dp[N-1][S-K*(N-1)*N/2]<<endl;}else{cout<<0<<endl;}}