結果

問題 No.2550 MORE! JUMP! MORE!
ユーザー ThetaTheta
提出日時 2024-03-06 18:15:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,559 ms / 2,000 ms
コード長 1,769 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 11,776 KB
実行使用メモリ 96,224 KB
最終ジャッジ日時 2024-03-06 18:16:00
合計ジャッジ時間 27,578 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,112 KB
testcase_01 AC 29 ms
10,112 KB
testcase_02 AC 30 ms
10,112 KB
testcase_03 AC 36 ms
10,112 KB
testcase_04 AC 30 ms
10,112 KB
testcase_05 AC 30 ms
10,112 KB
testcase_06 AC 31 ms
10,112 KB
testcase_07 AC 30 ms
10,112 KB
testcase_08 AC 30 ms
10,112 KB
testcase_09 AC 29 ms
10,112 KB
testcase_10 AC 31 ms
10,112 KB
testcase_11 AC 31 ms
10,112 KB
testcase_12 AC 29 ms
10,112 KB
testcase_13 AC 30 ms
10,112 KB
testcase_14 AC 31 ms
10,112 KB
testcase_15 AC 31 ms
10,112 KB
testcase_16 AC 30 ms
10,112 KB
testcase_17 AC 30 ms
10,112 KB
testcase_18 AC 30 ms
10,112 KB
testcase_19 AC 30 ms
10,112 KB
testcase_20 AC 1,015 ms
60,036 KB
testcase_21 AC 553 ms
37,308 KB
testcase_22 AC 189 ms
20,400 KB
testcase_23 AC 877 ms
54,336 KB
testcase_24 AC 1,502 ms
95,952 KB
testcase_25 AC 933 ms
56,688 KB
testcase_26 AC 704 ms
52,276 KB
testcase_27 AC 1,274 ms
71,316 KB
testcase_28 AC 1,063 ms
63,912 KB
testcase_29 AC 772 ms
52,840 KB
testcase_30 AC 1,535 ms
96,224 KB
testcase_31 AC 1,536 ms
96,224 KB
testcase_32 AC 1,552 ms
96,224 KB
testcase_33 AC 1,531 ms
96,224 KB
testcase_34 AC 1,545 ms
96,224 KB
testcase_35 AC 1,544 ms
96,224 KB
testcase_36 AC 1,559 ms
96,224 KB
testcase_37 AC 1,529 ms
96,224 KB
testcase_38 AC 1,535 ms
96,224 KB
testcase_39 AC 1,537 ms
96,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cache
from re import M
import sys


def printe(*args, end="\n", **kwargs):
    print(*args, end=end, file=sys.stderr, **kwargs)


@cache
def pow_mod(base: int, idx: int, mod: int) -> int:
    if idx == 0:
        return 1 % mod

    if idx == 1:
        return base % mod

    if idx % 2 == 0:
        idx //= 2
        base **= 2
        base %= mod
        return pow_mod(base, idx, mod)

    return base * pow_mod(base, idx - 1, mod)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 998244353
    if N == 1:
        print(A[0] % MOD)
        return
    # 書き出してみると各ステップごとに到達するときの上り方のパターン数は、kステップについて考えると二項係数になっている
    # →ステップ数 ↓行動回数
    # 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    # 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
    # 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0
    # 0 0 0 1 3 6 10 15 21 28 36 45 55 66 78 91 0
    # 0 0 0 0 1 4 10 20 35 56 84 120 165 220 286 364 0
    # ...

    # kステップ目におけるi*A_kの和を求めるには、kC0+2*kC1+3*kC2+...+(k+1)kCk
    # がA_kの係数になるが、これは二項係数に関する和の公式から
    # https://a-iine.net/combination/
    # (k+2)*2^(k-1)と整理できる

    patterns = A[0] * pow_mod(2, N - 2, MOD)
    for idx, a_elm in enumerate(A[1:], 1):
        printe(patterns)
        if idx < N - 1:
            patterns += (idx + 2) * pow_mod(2, idx - 1, MOD) * \
                a_elm * pow_mod(2, N - idx - 2, MOD)
        else:
            patterns += (idx + 2) * pow_mod(2, idx - 1, MOD) * \
                a_elm
        patterns %= MOD

    print(patterns)


if __name__ == "__main__":
    main()
0