結果

問題 No.314 ケンケンパ
ユーザー neterukunneterukun
提出日時 2019-06-03 04:24:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 586 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 11,932 KB
実行使用メモリ 159,252 KB
最終ジャッジ日時 2023-10-17 23:12:31
合計ジャッジ時間 7,598 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 29 ms
10,176 KB
testcase_02 AC 30 ms
10,176 KB
testcase_03 AC 30 ms
10,180 KB
testcase_04 AC 29 ms
10,176 KB
testcase_05 AC 29 ms
10,176 KB
testcase_06 AC 29 ms
10,176 KB
testcase_07 AC 29 ms
10,176 KB
testcase_08 AC 30 ms
10,176 KB
testcase_09 AC 30 ms
10,180 KB
testcase_10 AC 30 ms
10,208 KB
testcase_11 AC 30 ms
10,220 KB
testcase_12 AC 30 ms
10,244 KB
testcase_13 AC 30 ms
10,292 KB
testcase_14 AC 37 ms
11,012 KB
testcase_15 AC 44 ms
11,624 KB
testcase_16 AC 64 ms
14,004 KB
testcase_17 AC 174 ms
25,132 KB
testcase_18 AC 809 ms
81,504 KB
testcase_19 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if n == 1:
    print(1) #ケン
    exit()
elif n == 2:
    print(2) #ケンケン、ケンパ
    exit()

# dp[i][j] := 長さiで終わるときの通り数
# jはケンかパーかをbit集合で管理
dp = [[0]*6 for i in range(n+1)]
# 初期化
dp[3][0] = 0
dp[3][1] = 0
dp[3][2] = 1
dp[3][3] = 0
dp[3][4] = 1
dp[3][5] = 0

for i in range(3, n):
    dp[i+1][4] = dp[i][1]
    dp[i+1][5] = dp[i][2]
    dp[i+1][2] = dp[i][4] + dp[i][5]
    dp[i+1][1] = dp[i][2]
    dp[i+1][2] %= MOD

ans = 0
for j in range(6):
    ans += dp[n][j]
print(ans % MOD)
0