結果

問題 No.269 見栄っ張りの募金活動
ユーザー HIcoderHIcoder
提出日時 2024-02-11 23:04:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 3,204 bytes
コンパイル時間 1,440 ms
コンパイル使用メモリ 112,616 KB
実行使用メモリ 52,860 KB
最終ジャッジ日時 2024-02-11 23:04:09
合計ジャッジ時間 3,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
34,556 KB
testcase_01 AC 33 ms
34,556 KB
testcase_02 AC 34 ms
34,812 KB
testcase_03 AC 35 ms
35,836 KB
testcase_04 AC 51 ms
42,620 KB
testcase_05 AC 34 ms
34,684 KB
testcase_06 AC 33 ms
34,556 KB
testcase_07 AC 80 ms
52,860 KB
testcase_08 AC 34 ms
34,556 KB
testcase_09 AC 40 ms
41,596 KB
testcase_10 AC 34 ms
34,684 KB
testcase_11 AC 39 ms
37,884 KB
testcase_12 AC 37 ms
40,060 KB
testcase_13 AC 41 ms
37,500 KB
testcase_14 AC 36 ms
36,988 KB
testcase_15 AC 39 ms
37,500 KB
testcase_16 AC 37 ms
39,676 KB
testcase_17 AC 34 ms
35,580 KB
testcase_18 AC 52 ms
45,564 KB
testcase_19 AC 39 ms
37,756 KB
testcase_20 AC 36 ms
35,708 KB
testcase_21 AC 36 ms
36,732 KB
testcase_22 AC 37 ms
36,220 KB
testcase_23 AC 34 ms
34,940 KB
testcase_24 AC 36 ms
36,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;

const int mod = 1e9+7;
struct mint {
  long long x; // typedef long long long long;
  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;}
  mint operator+(const mint a) const { return mint(*this) += a;}//後ろのconstはメンバxを変更しないことを示す
  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 a.x==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();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;}
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;}



struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


combination comb(2*1000000+10);


//mint dp[105][2*10000+10];

int main(){
    int N,S,K;
    cin>>N>>S>>K;

    /*
    for(int s=0;s<=S;s++){
      dp[0][s]=1;//0人目はs円の寄付をする
    }

    for(int i=1;i<N;i++){
      vector<mint> sumS(S+1,0);
      sumS[0]=dp[i-1][0];
      for(int x=1;x<=S;x++){
        sumS[x]=sumS[x-1]+dp[i-1][x];
      }

      for(int c=1;c<=S;c++){
        if(c-K>=0){
          //x=0,1,2,3,...,c-K円
          dp[i][c]=sumS[c-K];
        }
      }
    }
    */

  vector<vector<mint>> g(N+1,vector<mint>(S+1,0));
  vector<vector<bool>> used(N+1,vector<bool>(S+1,0));
   

  auto dfs=[&](auto f,int i,int T)->mint{
    
    if(i==0) return T==0; //生徒0は0円を払う1通り
    if(used[i][T]) return g[i][T];
    used[i][T]=1;
    mint res=0;
    
    if(i-1>=0){
      //i人目は1円も払わない
      res+=f(f,i-1,T);
    }
    if(T-i>=0){
      //i人目が1円おおく払う.その結果,残りi+1~1人目が1円おおく払う.
      res+=f(f,i,T-i);
    }
    //g[i][T]=f(f,i-1,T-K*(N-i))+f(f,i,T-(N-i));
    g[i][T]=res;
    return g[i][T];
  };
  S-=N*(N-1)/2*K;//デフォルトで払ってしまう

  mint ans;

  if(S<0){
    ans=0;
  }else{
    ans=dfs(dfs,N,S);
  }
  cout<<ans<<endl;


    
}
0