結果

問題 No.314 ケンケンパ
ユーザー norioc
提出日時 2024-08-22 20:04:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 878 ms / 1,000 ms
コード長 688 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 172,436 KB
最終ジャッジ日時 2024-08-22 20:04:51
合計ジャッジ時間 6,130 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from enum import IntEnum, auto


# ステート遷移
class E(IntEnum):
    K = 0        # ケン
    KK = auto()  # ケンケン
    P = auto()   # パ

    def nexts(self):
        match self:
            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)]
dp[0][E.K] = 1
for i in range(N-1):
    for fm, to in E.states():
        dp[i+1][to] += dp[i][fm]
        dp[i+1][to] %= MOD

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