結果

問題 No.1555 Constructed Balancing Sequence
ユーザー chineristACchineristAC
提出日時 2021-01-11 03:58:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 100,852 KB
最終ジャッジ日時 2023-09-04 22:02:15
合計ジャッジ時間 6,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,316 KB
testcase_01 AC 75 ms
71,304 KB
testcase_02 AC 75 ms
71,368 KB
testcase_03 AC 75 ms
71,452 KB
testcase_04 AC 74 ms
71,160 KB
testcase_05 AC 74 ms
71,152 KB
testcase_06 AC 76 ms
71,368 KB
testcase_07 AC 76 ms
71,308 KB
testcase_08 AC 75 ms
71,400 KB
testcase_09 AC 75 ms
71,364 KB
testcase_10 AC 76 ms
71,248 KB
testcase_11 AC 76 ms
71,304 KB
testcase_12 AC 116 ms
100,144 KB
testcase_13 AC 116 ms
100,192 KB
testcase_14 AC 116 ms
100,532 KB
testcase_15 AC 111 ms
100,032 KB
testcase_16 AC 116 ms
100,216 KB
testcase_17 AC 84 ms
76,376 KB
testcase_18 AC 113 ms
100,460 KB
testcase_19 AC 114 ms
100,552 KB
testcase_20 AC 113 ms
100,660 KB
testcase_21 AC 112 ms
100,444 KB
testcase_22 AC 113 ms
100,476 KB
testcase_23 AC 116 ms
100,248 KB
testcase_24 AC 115 ms
100,848 KB
testcase_25 AC 114 ms
100,852 KB
testcase_26 AC 118 ms
100,788 KB
testcase_27 AC 114 ms
100,236 KB
testcase_28 AC 105 ms
92,852 KB
testcase_29 AC 110 ms
97,304 KB
testcase_30 AC 110 ms
97,360 KB
testcase_31 AC 100 ms
88,712 KB
testcase_32 AC 111 ms
97,708 KB
testcase_33 AC 111 ms
100,228 KB
testcase_34 AC 97 ms
88,952 KB
testcase_35 AC 102 ms
90,468 KB
testcase_36 AC 106 ms
92,796 KB
testcase_37 AC 105 ms
94,804 KB
testcase_38 AC 74 ms
71,472 KB
testcase_39 AC 74 ms
71,156 KB
testcase_40 AC 78 ms
71,404 KB
testcase_41 AC 74 ms
71,416 KB
testcase_42 AC 77 ms
72,656 KB
testcase_43 AC 110 ms
100,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#maspyさんのコード(https://yukicoder.me/submissions/602281)をもとにつくったO(N)解

def check(N,K,A):
    import itertools
    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
        res = 1
        for n in range(N - 2, -1, -1):
            if v < S[n] + A[n] - 1:
                low = A[n]
            else:
                low = -K
            #print(A[n]+1-low)
            res *= (A[n]+1-low)
            res %= MOD
            v = max(A[n]-1,v//2)

        return res

    return main(N,K,A)

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