結果

問題 No.533 Mysterious Stairs
ユーザー alexara1123alexara1123
提出日時 2019-07-09 15:20:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,497 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 817,664 KB
最終ジャッジ日時 2024-04-20 09:18:27
合計ジャッジ時間 3,907 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
11,136 KB
testcase_01 AC 26 ms
11,136 KB
testcase_02 AC 26 ms
11,136 KB
testcase_03 AC 26 ms
11,008 KB
testcase_04 AC 26 ms
11,008 KB
testcase_05 AC 27 ms
11,008 KB
testcase_06 AC 27 ms
11,008 KB
testcase_07 AC 28 ms
11,008 KB
testcase_08 AC 25 ms
11,008 KB
testcase_09 AC 28 ms
11,008 KB
testcase_10 AC 26 ms
11,008 KB
testcase_11 AC 27 ms
11,008 KB
testcase_12 AC 30 ms
11,264 KB
testcase_13 AC 33 ms
11,520 KB
testcase_14 AC 34 ms
11,648 KB
testcase_15 AC 40 ms
12,544 KB
testcase_16 AC 58 ms
16,384 KB
testcase_17 AC 93 ms
27,136 KB
testcase_18 AC 148 ms
46,464 KB
testcase_19 AC 196 ms
65,536 KB
testcase_20 MLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp =  [ [i for i in range(3)] for i in range(N+1)]

for i in range(N):
    for j in range(3):
        dp[i+1][0] += dp[i][2] + dp[i][1]
        dp[i+1][1] += dp[i][0] + dp[i][2]
        dp[i+1][2] += dp[i][1] + dp[i][2]
#
#ans = 0
#or i in range(3):
#    ans += dp[N][i]
#print(ans)


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