結果

問題 No.314 ケンケンパ
ユーザー terrafarmterrafarm
提出日時 2020-12-14 09:09:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 431 ms / 1,000 ms
コード長 934 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 177,588 KB
最終ジャッジ日時 2023-10-20 04:47:50
合計ジャッジ時間 4,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 431 ms
176,116 KB
testcase_01 AC 98 ms
79,744 KB
testcase_02 AC 98 ms
79,752 KB
testcase_03 AC 98 ms
79,744 KB
testcase_04 AC 97 ms
79,752 KB
testcase_05 AC 97 ms
79,748 KB
testcase_06 AC 96 ms
79,756 KB
testcase_07 AC 96 ms
79,744 KB
testcase_08 AC 96 ms
79,756 KB
testcase_09 AC 98 ms
79,704 KB
testcase_10 AC 103 ms
80,532 KB
testcase_11 AC 104 ms
80,560 KB
testcase_12 AC 106 ms
80,580 KB
testcase_13 AC 108 ms
80,580 KB
testcase_14 AC 106 ms
80,596 KB
testcase_15 AC 107 ms
80,592 KB
testcase_16 AC 112 ms
80,752 KB
testcase_17 AC 143 ms
90,920 KB
testcase_18 AC 267 ms
127,852 KB
testcase_19 AC 431 ms
177,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import logging
import sys
from inspect import currentframe

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

logging.basicConfig(level=logging.DEBUG)


def dbg(*args):
    id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    logging.debug(
        ", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args)
    )


def main():

    # 直前のケンの数で場合分け
    mod = 10 ** 9 + 7
    n = int(input())
    dp = [[0] * 3 for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(n):
        for j in range(3):
            if i == 0 and j != 0:
                continue
            for nj in range(3):
                if nj == (j + 1) % 3 or (j == 1 and nj == 0):
                    dp[i + 1][nj] += dp[i][j]
                    dp[i + 1][nj] %= mod
    s = 0
    for i in range(3):
        s += dp[n][i]
    s %= mod
    print(s)


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