結果
問題 | No.314 ケンケンパ |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
from enum import IntEnum, autofrom functools import cacheclass 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@cachedef states():res = []for fm in E:for to in fm.nexts():res.append((fm, to))return resdef state_dp(n: int, op, e, init: dict):dp = [e() for _ in range(len(E))]for k, v in init.items():dp[k] = vfor _ in range(n):pp = [e() for _ in range(len(E))]dp, pp = pp, dpfor fm, to in E.states():dp[to] = op(dp[to], pp[fm])return dpdef op(a, b):return (a + b) % MODMOD = 10**9 + 7N = int(input())res = state_dp(N, op, int, {E.S: 1})ans = sum(res) % MODprint(ans)