結果

問題 No.1474 かさまJ
ユーザー 👑 NachiaNachia
提出日時 2021-04-10 00:32:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 2,500 ms
コード長 1,291 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 210,276 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2023-09-07 19:28:40
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 89 ms
7,504 KB
testcase_06 AC 22 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 126 ms
7,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 178 ms
7,928 KB
testcase_14 AC 45 ms
4,376 KB
testcase_15 AC 25 ms
4,380 KB
testcase_16 AC 7 ms
4,404 KB
testcase_17 AC 54 ms
5,912 KB
testcase_18 AC 236 ms
8,816 KB
testcase_19 AC 284 ms
9,500 KB
testcase_20 AC 301 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ll MOD = 1000000007;
using mll = atcoder::static_modint<1000000007>;

int N,P,Q,L;
int S[40];
vector<vector<mll>> dp;

vector<mll> F,I,iF;
mll C(int n,int r){ return F[n]*iF[r]*iF[n-r]; }

void initC(int Z){
  F.resize(Z+1);
  F[0]=1; for(int i=1; i<=Z; i++) F[i]=F[i-1]*i;
  I.resize(Z+1);
  I[1]=1; for(int i=2; i<=Z; i++) I[i]=-(MOD/i*I[MOD%i]);
  iF.resize(Z+1);
  iF[0]=1; for(int i=1; i<=Z; i++) iF[i]=iF[i-1]*I[i];
}

int main(){
  scanf("%d%d%d%d",&N,&P,&Q,&L);
  rep(i,N) scanf("%d",&S[i]);
  dp.assign(N+1,vector<mll>(Q+1,0));
  dp[0][0]=1;
  rep(i,N){
    vector<vector<mll>> buf = dp;
    rep(j,N+1) rep(q,Q) dp[j][q+1] += dp[j][q];
    rep(j,N) for(int q=1; q<=Q; q++){
      int l = max(0,q-S[i]);
      int r = q-1;
      if(l==0) buf[j+1][q] += dp[j][r];
      else buf[j+1][q] += dp[j][r] - dp[j][l-1];
    }
    dp = move(buf);
  }

  initC(40000);

  mll ans=0;

  for(int i=0; i<=N; i++){
    if(i*L>P+Q) break;
    for(int q=0; q<=Q; q++){
      int freeP = P - (i*L-q);
      if(freeP<0) continue;
      ans += dp[i][q] * C(freeP+N-1,N-1);
    }
  }

  printf("%u\n",ans.val());

  return 0;
}
0