結果

問題 No.1555 Constructed Balancing Sequence
ユーザー chineristACchineristAC
提出日時 2021-01-12 04:02:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 86,624 KB
実行使用メモリ 98,988 KB
最終ジャッジ日時 2023-09-04 22:03:12
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,208 KB
testcase_01 AC 76 ms
71,104 KB
testcase_02 AC 76 ms
71,000 KB
testcase_03 AC 75 ms
71,208 KB
testcase_04 AC 76 ms
71,172 KB
testcase_05 AC 74 ms
71,088 KB
testcase_06 AC 76 ms
71,056 KB
testcase_07 AC 77 ms
71,060 KB
testcase_08 AC 77 ms
70,804 KB
testcase_09 AC 77 ms
71,204 KB
testcase_10 AC 76 ms
71,184 KB
testcase_11 AC 76 ms
71,204 KB
testcase_12 AC 118 ms
98,288 KB
testcase_13 AC 117 ms
98,048 KB
testcase_14 AC 118 ms
98,204 KB
testcase_15 AC 107 ms
97,736 KB
testcase_16 AC 119 ms
98,644 KB
testcase_17 AC 84 ms
76,188 KB
testcase_18 AC 110 ms
98,500 KB
testcase_19 AC 111 ms
98,408 KB
testcase_20 AC 112 ms
98,760 KB
testcase_21 AC 113 ms
98,364 KB
testcase_22 AC 112 ms
98,648 KB
testcase_23 AC 115 ms
98,988 KB
testcase_24 AC 113 ms
98,604 KB
testcase_25 AC 109 ms
98,380 KB
testcase_26 AC 115 ms
98,972 KB
testcase_27 AC 115 ms
98,824 KB
testcase_28 AC 101 ms
90,644 KB
testcase_29 AC 107 ms
95,776 KB
testcase_30 AC 107 ms
95,480 KB
testcase_31 AC 96 ms
86,792 KB
testcase_32 AC 116 ms
96,064 KB
testcase_33 AC 111 ms
98,040 KB
testcase_34 AC 98 ms
86,892 KB
testcase_35 AC 98 ms
88,440 KB
testcase_36 AC 102 ms
90,304 KB
testcase_37 AC 105 ms
92,652 KB
testcase_38 AC 76 ms
71,108 KB
testcase_39 AC 77 ms
70,996 KB
testcase_40 AC 76 ms
71,004 KB
testcase_41 AC 77 ms
71,104 KB
testcase_42 AC 76 ms
71,136 KB
testcase_43 AC 109 ms
98,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

        res = 1

        for n in range(N-2,-1,-1):
            tmp = A[n] - 1 + S[n]
            flag = False
            for j in range(n+1,N):
                if tmp > K:
                    break
                if A[j]-1 >= tmp:
                    flag = True
                    break
                tmp *= 2
            if flag:
                res *= (A[n]+1+K)
                res %= MOD

        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