結果

問題 No.1555 Constructed Balancing Sequence
ユーザー chineristACchineristAC
提出日時 2021-01-09 03:14:41
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,285 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 848,236 KB
最終ジャッジ日時 2023-09-04 22:01:07
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,876 KB
testcase_01 AC 117 ms
77,604 KB
testcase_02 AC 74 ms
70,988 KB
testcase_03 AC 74 ms
70,956 KB
testcase_04 AC 74 ms
71,128 KB
testcase_05 AC 75 ms
71,168 KB
testcase_06 AC 74 ms
71,000 KB
testcase_07 AC 76 ms
71,128 KB
testcase_08 AC 74 ms
71,312 KB
testcase_09 AC 81 ms
75,696 KB
testcase_10 AC 74 ms
71,116 KB
testcase_11 AC 85 ms
75,804 KB
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def perferct_solve(N,K,A):
    mod = 998244353

    diff = [A[i] for i in range(N)]
    cum = [A[i] for i in range(N)]
    S = A[0]
    for i in range(1,N):
        diff[i] = S - A[i]
        if diff[i] < 0:
            return 0
        S += A[i]
        cum[i] = S

    dp = [[0 for up in range(3*K+1)] for i in range(N)]

    for up in range(3*K+1):
        first = A[0] - up
        if -K<=first<=K:
            dp[0][up] = 1
        if up:
            dp[0][up] += dp[0][up-1]
            dp[0][up] %= mod

    for i in range(1,N):
        for up in range(3*K+1):
            if diff[i] and up<=A[i]+K:
                dp[i][up] += dp[i-1][0]
                dp[i][up] %= mod

            if up%2==diff[i] and diff[i]<=up<=cum[i]+2*K:
                dp[i][up] += dp[i-1][3*K] - dp[i-1][(up+diff[i])//2]
                dp[i][up] %= mod

            if diff[i]<=1 and diff[i]<=up<=cum[i]+2*K:
                pre_up_L = max(diff[i],-K+up-A[i])
                dp[i][up] += dp[i-1][(up+diff[i])//2] - dp[i-1][pre_up_L-1] * (pre_up_L>0)
                dp[i][up] %= mod

            if up:
                dp[i][up] += dp[i][up-1]
                dp[i][up] %= mod

    return dp[N-1][0]

N,K = map(int,input().split())
A = list(map(int,input().split()))
print(perferct_solve(N,K,A))
0