結果

問題 No.314 ケンケンパ
ユーザー norioc
提出日時 2025-04-02 20:02:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 350 ms / 1,000 ms
コード長 1,027 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 77,356 KB
最終ジャッジ日時 2025-04-02 20:02:20
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from enum import IntEnum, auto
from functools import cache


class E(IntEnum):
    S = 0        # 開始
    K = auto()   # ケン
    KK = auto()  # ケンケン
    P = auto()   # パ

    def nexts(self):
        match self:
            case E.S: return [E.K]
            case E.K: return [E.KK, E.P]
            case E.KK: return [E.P]
            case E.P: return [E.K]
        assert False

    @staticmethod
    @cache
    def states():
        res = []
        for fm in E:
            for to in fm.nexts():
                res.append((fm, to))

        return res


def state_dp(n: int, op, e, init: dict):
    dp = [e() for _ in range(len(E))]
    for k, v in init.items():
        dp[k] = v

    for _ in range(n):
        pp = [e() for _ in range(len(E))]
        dp, pp = pp, dp
        for fm, to in E.states():
            dp[to] = op(dp[to], pp[fm])

    return dp


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


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

res = state_dp(N, op, int, {E.S: 1})
ans = sum(res) % MOD
print(ans)
0