結果

問題 No.533 Mysterious Stairs
ユーザー alexara1123alexara1123
提出日時 2019-07-09 15:20:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,514 ms / 5,000 ms
コード長 1,213 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 128,512 KB
最終ジャッジ日時 2024-04-20 09:19:30
合計ジャッジ時間 15,450 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 30 ms
10,880 KB
testcase_05 AC 30 ms
11,008 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 29 ms
11,008 KB
testcase_08 AC 30 ms
11,008 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 32 ms
10,880 KB
testcase_11 AC 32 ms
10,880 KB
testcase_12 AC 32 ms
11,008 KB
testcase_13 AC 32 ms
10,880 KB
testcase_14 AC 33 ms
10,880 KB
testcase_15 AC 35 ms
11,008 KB
testcase_16 AC 40 ms
11,136 KB
testcase_17 AC 49 ms
11,520 KB
testcase_18 AC 58 ms
11,776 KB
testcase_19 AC 64 ms
12,032 KB
testcase_20 AC 412 ms
24,064 KB
testcase_21 AC 458 ms
25,472 KB
testcase_22 AC 1,380 ms
55,936 KB
testcase_23 AC 3,492 ms
127,104 KB
testcase_24 AC 3,514 ms
128,512 KB
testcase_25 AC 421 ms
24,192 KB
testcase_26 AC 3,043 ms
112,256 KB
testcase_27 AC 919 ms
40,704 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