結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 29 ms
10,192 KB
testcase_02 AC 29 ms
10,192 KB
testcase_03 AC 28 ms
10,200 KB
testcase_04 AC 28 ms
10,192 KB
testcase_05 AC 28 ms
10,192 KB
testcase_06 AC 29 ms
10,192 KB
testcase_07 AC 29 ms
10,192 KB
testcase_08 AC 29 ms
10,192 KB
testcase_09 AC 30 ms
10,200 KB
testcase_10 AC 30 ms
10,228 KB
testcase_11 AC 30 ms
10,248 KB
testcase_12 AC 30 ms
10,272 KB
testcase_13 AC 30 ms
10,312 KB
testcase_14 AC 35 ms
10,952 KB
testcase_15 AC 41 ms
11,496 KB
testcase_16 AC 61 ms
13,648 KB
testcase_17 AC 168 ms
23,604 KB
testcase_18 AC 768 ms
74,040 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]*4 for i in range(n+1)]
# 初期化
dp[3][0] = 0
dp[3][1] = 1
dp[3][2] = 1
dp[3][3] = 0

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

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