結果

問題 No.533 Mysterious Stairs
ユーザー alexara1123alexara1123
提出日時 2019-07-09 15:20:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 1,213 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 91,524 KB
最終ジャッジ日時 2024-04-20 09:18:22
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,752 KB
testcase_01 AC 42 ms
52,604 KB
testcase_02 AC 38 ms
52,320 KB
testcase_03 AC 38 ms
53,428 KB
testcase_04 AC 38 ms
52,756 KB
testcase_05 AC 39 ms
52,344 KB
testcase_06 AC 39 ms
52,920 KB
testcase_07 AC 38 ms
52,588 KB
testcase_08 AC 38 ms
53,764 KB
testcase_09 AC 37 ms
52,900 KB
testcase_10 AC 40 ms
53,288 KB
testcase_11 AC 42 ms
53,996 KB
testcase_12 AC 42 ms
53,940 KB
testcase_13 AC 49 ms
60,860 KB
testcase_14 AC 49 ms
61,732 KB
testcase_15 AC 59 ms
67,272 KB
testcase_16 AC 59 ms
67,528 KB
testcase_17 AC 60 ms
67,940 KB
testcase_18 AC 59 ms
68,424 KB
testcase_19 AC 59 ms
67,676 KB
testcase_20 AC 64 ms
70,604 KB
testcase_21 AC 66 ms
70,852 KB
testcase_22 AC 79 ms
77,248 KB
testcase_23 AC 106 ms
91,524 KB
testcase_24 AC 105 ms
90,364 KB
testcase_25 AC 66 ms
70,912 KB
testcase_26 AC 99 ms
88,568 KB
testcase_27 AC 72 ms
73,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000000)
N = int(input())


memo1 = [ -1 for i in range(N+1)]
memo2 = [ -1 for i in range(N+1)]
memo3 = [ -1 for i in range(N+1)]

MOD = 10**9 + 7

def r1(n):
    if n == 1:
        return 1
    elif n == 2:
        return 0
    elif n == 3:
        return 1
    else:
        if memo2[n-1] == -1:
            memo2[n-1] = r2(n-1) % MOD
        if memo3[n-1] == -1:
            memo3[n-1] = r3(n-1)%MOD
        return (memo2[n-1] + memo3[n-1]) % MOD
        
def r2(n):
    if n == 1:
        return 0
    elif n == 2:
        return 1
    elif n == 3:
        return 1
    else:
        if memo1[n-2] == -1:
            memo1[n-2] = r1(n-2) % MOD
        if memo3[n-2] == -1:
            memo3[n-2] = r3(n-2) % MOD
        return (memo1[n-2] + memo3[n-2]) % MOD

def r3(n):
    if n == 1:
        return 0
    elif n == 2:
        return 0
    elif n == 3:
        return 1
    else:
        if memo1[n-3] == -1:
            memo1[n-3] = r1(n-3) % MOD 
        if memo2[n-3] == -1:
            memo2[n-3] = r2(n-3) % MOD
        return (memo1[n-3] + memo2[n-3]) % MOD



def r(n):
    return (r1(n) + r2(n) + r3(n)) % MOD
for i in range(4,N):
    r(i)

print(r(N))
          
0