結果

問題 No.314 ケンケンパ
ユーザー FromBooskaFromBooska
提出日時 2023-10-15 15:15:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 1,000 ms
コード長 403 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 67,172 KB
最終ジャッジ日時 2024-09-16 22:00:53
合計ジャッジ時間 1,857 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
65,992 KB
testcase_01 AC 33 ms
52,952 KB
testcase_02 AC 31 ms
53,224 KB
testcase_03 AC 32 ms
52,944 KB
testcase_04 AC 33 ms
52,940 KB
testcase_05 AC 32 ms
52,196 KB
testcase_06 AC 33 ms
52,824 KB
testcase_07 AC 33 ms
53,792 KB
testcase_08 AC 37 ms
52,216 KB
testcase_09 AC 38 ms
51,888 KB
testcase_10 AC 36 ms
52,396 KB
testcase_11 AC 37 ms
53,828 KB
testcase_12 AC 39 ms
52,888 KB
testcase_13 AC 35 ms
52,796 KB
testcase_14 AC 37 ms
59,440 KB
testcase_15 AC 37 ms
59,232 KB
testcase_16 AC 38 ms
59,464 KB
testcase_17 AC 38 ms
59,488 KB
testcase_18 AC 45 ms
62,212 KB
testcase_19 AC 51 ms
67,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# やり方違った気がするが1次元dp
# dp[i]Pを置く場合数、答えは最後の3項の合計

N = int(input())
mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
for i in range(N+1):
    dp[i] %= mod
    if i+2 <= N:
        dp[i+2] += dp[i]
    if i+3 <= N:
        dp[i+3] += dp[i]
if N == 1:
    ans = 1
elif N == 2:
    ans = 2
elif N >= 3:
    ans = dp[N]+dp[N-1]+dp[N-2]
    ans %= mod
print(ans)
0