結果

問題 No.314 ケンケンパ
ユーザー sue_charosue_charo
提出日時 2017-04-14 16:29:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,050 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 10,732 KB
実行使用メモリ 212,604 KB
最終ジャッジ日時 2023-09-25 19:18:22
合計ジャッジ時間 6,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 15 ms
7,900 KB
testcase_02 AC 16 ms
7,756 KB
testcase_03 AC 16 ms
7,952 KB
testcase_04 AC 16 ms
7,752 KB
testcase_05 AC 15 ms
7,884 KB
testcase_06 AC 15 ms
7,928 KB
testcase_07 AC 15 ms
7,824 KB
testcase_08 AC 16 ms
7,848 KB
testcase_09 AC 16 ms
7,904 KB
testcase_10 AC 16 ms
8,188 KB
testcase_11 AC 16 ms
8,148 KB
testcase_12 AC 17 ms
8,380 KB
testcase_13 AC 17 ms
8,320 KB
testcase_14 AC 23 ms
9,236 KB
testcase_15 AC 29 ms
10,312 KB
testcase_16 AC 46 ms
13,296 KB
testcase_17 AC 140 ms
28,516 KB
testcase_18 AC 616 ms
105,852 KB
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7

N = int(input())
# 状態遷移 けん2回目→ぱ、けん1回目→けん2回目 or ぱ、ぱ→けん1回目

memo = [[0] * N for __ in range(3)]


def solve():
    if N == 1:
        return 1

    # state=0 ken2nd, state=1 ken1st, state=2 pa
    def move(state=1, now=2):
        global memo

        if now == N:
            if state == 0:
                return 1
            elif state == 1:
                return 2
            elif state == 2:
                return 1

        if memo[state][now] != 0:
            return memo[state][now]
        else:
            if state == 0:
                ret = move(2, now + 1)
            elif state == 1:
                ret = move(0, now + 1) + move(2, now + 1)
            elif state == 2:
                ret = move(1, now + 1)
            
            if ret >= mod:
                ret %= mod
            
            memo[state][now] = ret
            return ret

    return move()

print(solve() % (10 ** 9 + 7))
0