結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー lloyzlloyz
提出日時 2022-12-09 00:20:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 344 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 60,800 KB
最終ジャッジ日時 2024-04-22 18:47:03
合計ジャッジ時間 1,741 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,712 KB
testcase_01 AC 38 ms
51,840 KB
testcase_02 AC 37 ms
52,224 KB
testcase_03 AC 37 ms
52,224 KB
testcase_04 AC 42 ms
52,096 KB
testcase_05 AC 38 ms
51,968 KB
testcase_06 AC 43 ms
58,496 KB
testcase_07 AC 49 ms
60,672 KB
testcase_08 AC 38 ms
51,968 KB
testcase_09 AC 38 ms
51,840 KB
testcase_10 AC 46 ms
60,800 KB
testcase_11 AC 49 ms
60,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
mod = 10**9 + 7

t = 1
DP = [0 for _ in range(3)]
NDP = [0 for _ in range(3)]
for i in range(n):
    idx = ord(s[i]) - ord('A')
    for j in range(3):
        if j == idx:
            NDP[j] = DP[j]
        else:
            NDP[j] = (DP[3 - j - idx] + t) % mod
    DP = NDP[:]
    t *= 2
    t %= mod
print(DP[0])
0