結果

問題 No.2147 ハノイの塔のおもちゃ
コンテスト
ユーザー trineutron
提出日時 2022-12-04 05:50:46
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 20 ms / 2,000 ms
+ 854µs
コード長 214 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 54 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2026-09-13 19:54:25
合計ジャッジ時間 1,526 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

mod = 10**9 + 7

n = int(input())
s = input()

ans = 0
last = 0
for c in s[::-1]:
    ans *= 2
    ans %= mod
    x = ord(c) - ord('A')
    if x != last:
        ans += 1
        last = (-x - last) % 3

print(ans)
0