結果

問題 No.1555 Constructed Balancing Sequence
ユーザー maspymaspy
提出日時 2021-01-11 00:26:59
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,192 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 23,576 KB
最終ジャッジ日時 2023-09-04 22:01:40
合計ジャッジ時間 4,405 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,592 KB
testcase_01 AC 19 ms
8,348 KB
testcase_02 AC 17 ms
8,256 KB
testcase_03 AC 17 ms
8,332 KB
testcase_04 AC 17 ms
8,248 KB
testcase_05 AC 17 ms
8,296 KB
testcase_06 AC 17 ms
8,216 KB
testcase_07 AC 16 ms
8,332 KB
testcase_08 AC 16 ms
8,328 KB
testcase_09 AC 16 ms
8,204 KB
testcase_10 AC 16 ms
8,328 KB
testcase_11 AC 17 ms
8,292 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 #

"""
とりあえず愚直。
O(N^3)だし計算過程で mod をとっていないので自明に落ちると思っていたが、通ってしまった。
"""

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)
        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
            for b in range(low, A[n] + 1):
                to = max(b - 1, v // 2)
                newdp[to] += dp[v]
        dp = newdp
    return sum(dp) % MOD

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

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