結果

問題 No.314 ケンケンパ
コンテスト
ユーザー norioc
提出日時 2026-07-16 04:31:18
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 790 ms / 1,000 ms
+ 195µs
コード長 768 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 249 ms
コンパイル使用メモリ 96,104 KB
実行使用メモリ 96,640 KB
最終ジャッジ日時 2026-07-16 04:31:44
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from enum import Enum, auto


def accum_dp(xs: list, f, op, e, init: dict):
    dp = init.copy()
    for x in xs:
        pp = {}
        dp, pp = pp, dp
        for fm_key, fm_val in pp.items():
            for to_key, to_val in f(fm_key, fm_val, x):
                dp[to_key] = op(dp.get(to_key, e), to_val)

    return dp


def op(a, b):
    return (a + b) % MOD


class E(Enum):
    K1 = auto()
    K2 = auto()
    PA = auto()


def f(k, v, x):
    match k:
        case E.K1:
            yield E.K2, v
            yield E.PA, v

        case E.K2:
            yield E.PA, v

        case E.PA:
            yield E.K1, v


MOD = 10**9 + 7
N = int(input())

init = {E.K1: 1}
dp = accum_dp(list(range(1, N)), f, op, 0, init)
ans = sum(dp.values()) % MOD
print(ans)
0