結果

問題 No.314 ケンケンパ
ユーザー norioc
提出日時 2024-08-23 01:29:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 747 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 180,460 KB
最終ジャッジ日時 2024-08-23 01:30:04
合計ジャッジ時間 6,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

from enum import IntEnum, auto


# ステート遷移
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
    def states():
        for fm in E:
            for to in fm.nexts():
                yield fm, to


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

dp = [[0] * len(E) for _ in range(N+1)]
dp[0][E.S] = 1
for i in range(N):
    for fm, to in E.states():
        dp[i+1][to] += dp[i][fm]
        dp[i+1][to] %= MOD

ans = sum(dp[N]) % MOD
print(ans)
0