結果

問題 No.1474 かさまJ
ユーザー gorugo30gorugo30
提出日時 2021-02-21 11:17:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,995 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 175,960 KB
実行使用メモリ 813,336 KB
最終ジャッジ日時 2023-10-19 12:42:46
合計ジャッジ時間 5,435 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 395 ms
15,104 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 150 ms
10,460 KB
testcase_06 AC 32 ms
4,804 KB
testcase_07 AC 245 ms
10,492 KB
testcase_08 AC 228 ms
8,836 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, MP, Mq, L;
    cin >> N >> MP >> Mq >> L;
    vector<int> S(N);
    for (int i = 0; i < N; i++){
        cin >> S[i];
    }

    vector<vector<long>> dp(MP + 1, vector<long>(Mq + 1, 0));
    for (int x = 0; x <= MP; x++){
        dp[x][0] = 1;
    }
    for (int y = 1; y <= min(S[0], Mq); y++){
        for (int x = 0; x <= MP; x++){
            if (x + y < L) continue;
            dp[x][y] = 1;
        }
    }
    for (int i = 1; i < N; i++){
        vector<vector<long>> q0(MP + 1, vector<long>(Mq + 1, 0)); // 0個のq
        vector<vector<long>> q1(MP + 1, vector<long>(Mq + 1, 0)); // 1個以上のq
        for (int y = 0; y <= Mq; y++){
            for (int x = 0; x <= MP; x++){
                q0[x][y] = dp[x][y];
                int X = min(x + L - 1, MP);
                int Y = x + y + L - X;
                if (y < Y && Y <= min(y + S[i], Mq)){
                    q1[X][Y] = (q1[X][Y] + dp[x][y]) % MOD;
                    Y = min(Mq, y + S[i]) + 1;
                    X = x + y + L - Y;
                    if (0 <= X && X <= MP && 0 <= Y && Y <= Mq){
                        q1[X][Y] = (q1[X][Y] - dp[x][y] + MOD) % MOD;
                    }
                }
            }
        }
        for (int y = 1; y <= Mq; y++){
            for (int x = 0; x < MP; x++){
                q1[x][y] = (q1[x][y] + q1[x + 1][y - 1]) % MOD;
            }
        }
        for (int y = 0; y <= Mq; y++){
            for (int x = 0; x <= MP; x++){
                if (x > 0){
                    q1[x][y] = (q1[x][y] + q1[x - 1][y]) % MOD;
                    q0[x][y] = (q0[x][y] + q0[x - 1][y]) % MOD;
                }
                dp[x][y] = (q1[x][y] + q0[x][y]) % MOD;
            }
        }
    }
    long ans = 0;
    for (int y = 0; y <= Mq; y++){
        ans = (ans + dp[MP][y]) % MOD;
    }
    cout << ans << endl;
}
0