結果

問題 No.1474 かさまJ
ユーザー carrot46carrot46
提出日時 2021-04-09 23:19:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 265 ms / 2,500 ms
コード長 2,427 bytes
コンパイル時間 3,481 ms
コンパイル使用メモリ 203,892 KB
最終ジャッジ日時 2025-01-20 15:12:52
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace atcoder;
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;
const ll INF = (1LL<<61);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

using mint = modint1000000007;
using vm = vector<mint>;
const ll MAX_N = ll(4e+5) + 10;
vm fact(MAX_N, mint(1)), fact_inv(MAX_N, mint(1)), n_inv(MAX_N, mint(1));
void makefact(){
    reps(i,2,MAX_N) fact[i] = fact[i-1] * mint::raw(i);
    fact_inv[MAX_N - 1] = fact[MAX_N - 1].inv();
    Rreps(i, MAX_N - 1, 1){
        fact_inv[i] = fact_inv[i + 1] * mint::raw(i + 1);
        n_inv[i + 1] = fact[i] * fact_inv[i + 1];
    }
}
mint nCm(ll n, ll m){
    if(m < 0) return 0;
    return fact[n] * fact_inv[n-m] * fact_inv[m];
}
mint nCm_inv(ll n, ll m){
    return fact[n-m] * fact[m] * fact_inv[n];
}

void pr(vector<vm> &dp){
    rep(i, N + 1){
        for(mint m : dp[i]) cout<<m.val()<<' ';
        cout<<endl;
    }
    cout<<endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    makefact();
    int mp, mq, L;
    cin>>N>>mp>>mq>>L;
    vec a(N);
    rep(i, N) cin>>a[i];
    vector<vm> dp(N + 1, vm(mq + 1));
    dp[0][0] = 1;
    rep(i, N){
        Rrep(j, N){
            vm plus(mq + 1);
            rep(k, mq) plus[k + 1] = dp[j][k];
            rep(k, mq) plus[k + 1] += plus[k];
            Rreps(k, mq + 1, a[i]) plus[k] -= plus[k - a[i]];
            rep(k, mq + 1) dp[j + 1][k] += plus[k];
        }
        //pr(dp);
    }
    mint res;
    rep(i, N + 1) {
        rep(j, mq + 1){
            int rest_P = mp - (L * i - j);
            res += dp[i][j] * nCm(N + rest_P - 1, rest_P);
        }
    }
    cout<<res.val()<<endl;
}
0