結果

問題 No.1474 かさまJ
ユーザー KudeKude
提出日時 2021-04-09 22:41:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,500 ms
コード長 2,767 bytes
コンパイル時間 7,219 ms
コンパイル使用メモリ 264,668 KB
実行使用メモリ 17,388 KB
最終ジャッジ日時 2023-09-07 12:16:41
合計ジャッジ時間 6,454 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,268 KB
testcase_01 AC 15 ms
11,420 KB
testcase_02 AC 15 ms
11,252 KB
testcase_03 AC 15 ms
11,196 KB
testcase_04 AC 15 ms
11,192 KB
testcase_05 AC 54 ms
15,064 KB
testcase_06 AC 22 ms
11,684 KB
testcase_07 AC 15 ms
11,212 KB
testcase_08 AC 15 ms
11,236 KB
testcase_09 AC 70 ms
15,064 KB
testcase_10 AC 17 ms
11,776 KB
testcase_11 AC 16 ms
11,496 KB
testcase_12 AC 15 ms
11,336 KB
testcase_13 AC 95 ms
15,540 KB
testcase_14 AC 48 ms
12,152 KB
testcase_15 AC 33 ms
11,644 KB
testcase_16 AC 17 ms
11,908 KB
testcase_17 AC 55 ms
13,748 KB
testcase_18 AC 99 ms
16,648 KB
testcase_19 AC 115 ms
17,128 KB
testcase_20 AC 118 ms
17,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint1000000007;

constexpr int FACT_SIZE = 1000000;
mint Fact[FACT_SIZE + 1];
mint iFact[FACT_SIZE + 1];
const auto fact_init = [] {
    Fact[0] = mint::raw(1);
    for(int i = 1; i <= FACT_SIZE; ++i) {
        Fact[i] = Fact[i-1] * i;
    }
    iFact[FACT_SIZE] = Fact[FACT_SIZE].inv();
    for(int i = FACT_SIZE; i; --i) {
        iFact[i-1] = iFact[i] * i;
    }
    return false;
}();

mint comb(int n, int k) {
    if (k == 0) return mint::raw(1);
    assert(n >= 0 && k >= 0);
    if (k > n) return mint::raw(0);
    return Fact[n] * iFact[n - k] * iFact[k];
}

mint fact(int n) {return Fact[n];}
mint perm(int n, int k) {
    assert(0 <= n);
    return Fact[n] * iFact[n - k];
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, P, Q, L;
    cin >> N >> P >> Q >> L;
    // gave to j persons, k qs used
    vector<vector<mint>> dp(N + 1, vector<mint>(Q + 1));
    vector<vector<mint>> ndp(N + 1, vector<mint>(Q + 1));
    dp[0][0] = 1;
    rep(i, N) {
        rep(j, N + 1) rep(k, Q + 1) ndp[j][k] = mint::raw(0);
        int s;
        cin >> s;
        rep(j, N + 1) rep(k, Q + 1) if (dp[j][k].val() != 0) {
            const mint v = dp[j][k];
            int p_rest = P - (j * L - k);
            int q_rest = Q - k;
            int nq_min = max(L - p_rest, 1);
            int nq_max = min(q_rest, s);
            if (nq_min <= nq_max) {
                int nk1 = k + nq_min;
                int nk2 = k + nq_max;
                if (nk1 < Q + 1) ndp[j+1][nk1] += v;
                if (nk2 + 1 < Q + 1) ndp[j+1][nk2 + 1] -= v;
            }
            {
                int nk1 = k;
                int nk2 = k;
                if (nk1 < Q + 1) ndp[j][nk1] += v;
                if (nk2 + 1 < Q + 1) ndp[j][nk2 + 1] -= v;
            }
        }
        rep(j, N + 1) {
            mint now;
            rep(k, Q + 1) {
                now += ndp[j][k];
                ndp[j][k] = now;
            }
        }
        swap(dp, ndp);
    }
    mint ans;
    rep(j, N + 1) rep(k, Q + 1) if (dp[j][k].val() != 0) {
        const mint v = dp[j][k];
        int p_rest = P - (j * L - k);
        ans += comb(p_rest + N - 1, N - 1) * v;
    }
    cout << ans.val() << '\n';
}
0