結果

問題 No.1555 Constructed Balancing Sequence
ユーザー maspymaspy
提出日時 2021-01-11 00:45:23
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,407 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 87,392 KB
実行使用メモリ 265,676 KB
最終ジャッジ日時 2023-09-04 22:01:46
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
75,500 KB
testcase_01 AC 84 ms
75,868 KB
testcase_02 AC 75 ms
71,076 KB
testcase_03 AC 76 ms
71,048 KB
testcase_04 AC 76 ms
70,916 KB
testcase_05 AC 76 ms
70,868 KB
testcase_06 AC 76 ms
70,872 KB
testcase_07 AC 77 ms
70,868 KB
testcase_08 AC 76 ms
70,980 KB
testcase_09 AC 80 ms
75,684 KB
testcase_10 AC 75 ms
71,072 KB
testcase_11 AC 84 ms
75,632 KB
testcase_12 TLE -
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 #

import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

def is_balanced(A, Acum):
    for a, b in zip(A[1:], Acum[1:]):
        if a > b:
            return False
    return True

def main(N, K, A):
    S = [0] + list(itertools.accumulate(A))
    if not is_balanced(A, S):
        return 0
    MAX = K + 10
    # x 以下の数列は対策済
    dp = [0] * (MAX + MAX + 1)
    v = A[-1] - 1
    dp[v] = 1
    for n in range(N - 2, -1, -1):
        newdp = [0] * (MAX + MAX + 1)
        imos = [0] * (MAX + MAX + 1)
        for v in range(-MAX, MAX + 1):
            if not dp[v]:
                continue
            if v < S[n] + A[n] - 1:
                low = A[n]
            else:
                low = -K
            L, R = low, min(A[n], v // 2 + 1)
            if L <= R:
                newdp[v // 2] += dp[v] * (R - L + 1) % MOD
            L, R = max(low, v // 2 + 2), A[n]
            L, R = L - 1, R - 1
            if L <= R:
                imos[L] += dp[v]
                imos[R + 1] -= dp[v]
        for i in range(-MAX, MAX):
            imos[i] %= MOD
            imos[i + 1] += imos[i]
            newdp[i] += imos[i]
            newdp[i] %= MOD
        dp = newdp
    return sum(dp) % MOD

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

print(main(N, K, A))
0