結果

問題 No.314 ケンケンパ
ユーザー irumo8202irumo8202
提出日時 2022-01-30 15:03:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 1,000 ms
コード長 700 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 171,232 KB
最終ジャッジ日時 2023-09-02 01:38:01
合計ジャッジ時間 6,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
171,232 KB
testcase_01 AC 227 ms
171,008 KB
testcase_02 AC 229 ms
171,148 KB
testcase_03 AC 227 ms
171,136 KB
testcase_04 AC 225 ms
171,064 KB
testcase_05 AC 224 ms
170,932 KB
testcase_06 AC 225 ms
171,080 KB
testcase_07 AC 223 ms
170,944 KB
testcase_08 AC 223 ms
170,916 KB
testcase_09 AC 226 ms
171,032 KB
testcase_10 AC 226 ms
171,032 KB
testcase_11 AC 225 ms
171,000 KB
testcase_12 AC 225 ms
171,180 KB
testcase_13 AC 224 ms
171,120 KB
testcase_14 AC 228 ms
171,152 KB
testcase_15 AC 227 ms
171,140 KB
testcase_16 AC 227 ms
171,184 KB
testcase_17 AC 229 ms
170,904 KB
testcase_18 AC 225 ms
171,096 KB
testcase_19 AC 228 ms
171,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Live as if you were to die tomorrow.
# Learn as if you were to live forever.
MOD = 10 ** 9 + 7


def solve():
    # dp[i][0] means that i-th one ended in "first ken".
    # dp[i][1] means that i-th one ended in "second ken".
    # dp[i][2] means that i-th one ended in "pa".
    dp = [[0, 0, 0] for _ in range(10 ** 6 + 1)]
    dp[1][0] = 1

    for i in range(2, 10 ** 6 + 1):
        dp[i][0] += dp[i - 1][2]
        dp[i][0] %= MOD
        dp[i][1] += dp[i - 1][0]
        dp[i][1] %= MOD
        dp[i][2] += dp[i - 1][0] + dp[i - 1][1]
        dp[i][2] %= MOD
    return dp


def main():
    N = int(input())

    dp = solve()
    print(sum(dp[N]) % MOD)


if __name__ == "__main__":
    main()
0