結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー rlangevinrlangevin
提出日時 2024-01-11 08:54:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 53,460 KB
最終ジャッジ日時 2024-01-11 08:54:28
合計ジャッジ時間 3,098 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = list(input())
two = [1] * (N + 1)
mod = 10 ** 9 + 7
for i in range(N):
    two[i + 1] = two[i] * 2 % mod

pre = [0] * 3
for i in range(N):
    dp = [0] * 3
    if S[i] == "A":
        dp[0] = pre[0]
        dp[1] = (pre[2] + two[i]) % mod
        dp[2] = (pre[1] + two[i]) % mod
    elif S[i] == "B":
        dp[1] = pre[1]
        dp[2] = (pre[0] + two[i]) % mod
        dp[0] = (pre[2] + two[i]) % mod
    else:
        dp[2] = pre[2]
        dp[1] = (pre[0] + two[i]) % mod
        dp[0] = (pre[1] + two[i]) % mod
    dp, pre = pre, dp
    
print(pre[0])
0