結果

問題 No.1474 かさまJ
ユーザー carrot46carrot46
提出日時 2021-04-09 23:19:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,500 ms
コード長 2,427 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 208,924 KB
実行使用メモリ 10,972 KB
最終ジャッジ日時 2023-09-07 13:07:38
合計ジャッジ時間 4,355 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,652 KB
testcase_01 AC 9 ms
7,724 KB
testcase_02 AC 9 ms
7,572 KB
testcase_03 AC 9 ms
7,672 KB
testcase_04 AC 9 ms
7,644 KB
testcase_05 AC 83 ms
10,120 KB
testcase_06 AC 22 ms
8,084 KB
testcase_07 AC 9 ms
7,800 KB
testcase_08 AC 10 ms
7,668 KB
testcase_09 AC 117 ms
9,860 KB
testcase_10 AC 14 ms
8,152 KB
testcase_11 AC 10 ms
8,144 KB
testcase_12 AC 10 ms
7,600 KB
testcase_13 AC 120 ms
10,148 KB
testcase_14 AC 44 ms
8,356 KB
testcase_15 AC 24 ms
7,996 KB
testcase_16 AC 13 ms
8,276 KB
testcase_17 AC 47 ms
9,184 KB
testcase_18 AC 154 ms
10,804 KB
testcase_19 AC 181 ms
10,972 KB
testcase_20 AC 187 ms
10,940 KB
権限があれば一括ダウンロードができます

ソースコード

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