結果

問題 No.2550 MORE! JUMP! MORE!
ユーザー ThetaTheta
提出日時 2024-03-06 18:14:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,713 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 96,220 KB
最終ジャッジ日時 2024-03-06 18:14:46
合計ジャッジ時間 27,807 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,112 KB
testcase_01 AC 29 ms
10,112 KB
testcase_02 AC 27 ms
10,112 KB
testcase_03 RE -
testcase_04 AC 30 ms
10,112 KB
testcase_05 AC 27 ms
10,112 KB
testcase_06 AC 27 ms
10,112 KB
testcase_07 AC 27 ms
10,112 KB
testcase_08 AC 27 ms
10,112 KB
testcase_09 AC 28 ms
10,112 KB
testcase_10 AC 30 ms
10,112 KB
testcase_11 AC 27 ms
10,112 KB
testcase_12 AC 26 ms
10,112 KB
testcase_13 AC 26 ms
10,112 KB
testcase_14 AC 27 ms
10,112 KB
testcase_15 AC 26 ms
10,112 KB
testcase_16 AC 28 ms
10,112 KB
testcase_17 AC 28 ms
10,112 KB
testcase_18 AC 27 ms
10,112 KB
testcase_19 AC 26 ms
10,112 KB
testcase_20 AC 957 ms
60,024 KB
testcase_21 AC 544 ms
37,296 KB
testcase_22 AC 179 ms
20,384 KB
testcase_23 AC 799 ms
54,320 KB
testcase_24 AC 1,439 ms
95,940 KB
testcase_25 AC 893 ms
56,680 KB
testcase_26 AC 668 ms
52,264 KB
testcase_27 AC 1,202 ms
71,304 KB
testcase_28 AC 1,036 ms
63,904 KB
testcase_29 AC 711 ms
52,836 KB
testcase_30 AC 1,461 ms
96,220 KB
testcase_31 AC 1,478 ms
96,216 KB
testcase_32 AC 1,462 ms
96,220 KB
testcase_33 AC 1,463 ms
96,216 KB
testcase_34 AC 1,454 ms
96,220 KB
testcase_35 AC 1,456 ms
96,216 KB
testcase_36 AC 1,459 ms
96,216 KB
testcase_37 AC 1,484 ms
96,216 KB
testcase_38 AC 1,465 ms
96,216 KB
testcase_39 AC 1,450 ms
96,216 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()))
    # 書き出してみると各ステップごとに到達するときの上り方のパターン数は、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)と整理できる

    MOD = 998244353
    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