結果
| 問題 |
No.314 ケンケンパ
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-04-03 02:14:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 378 ms / 1,000 ms |
| コード長 | 1,233 bytes |
| コンパイル時間 | 346 ms |
| コンパイル使用メモリ | 82,420 KB |
| 実行使用メモリ | 85,112 KB |
| 最終ジャッジ日時 | 2025-04-03 02:14:56 |
| 合計ジャッジ時間 | 3,849 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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(xs: list, op, e, init: dict):
dp = [e for _ in range(len(E))]
for k, v in init.items():
dp[k] = v
for x in xs:
pp = [e for _ in range(len(E))]
dp, pp = pp, dp
for fm, to in E.states():
if not is_valid(to, pp[fm], x): continue
dp[to] = op(to, dp[to], fm, pp[fm], x)
return dp
def is_valid(to: E, fm_v, v) -> bool:
return True
def op(to: E, to_v, fm: E, fm_v, v):
return (to_v + fm_v) % MOD
MOD = 10**9 + 7
N = int(input())
dp = state_dp(list(range(N)), op, 0, {E.S: 1})
ans = sum(dp) % MOD
print(ans)
norioc