結果
問題 | No.2147 ハノイの塔のおもちゃ |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:25:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 468 bytes |
コンパイル時間 | 330 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 54,200 KB |
最終ジャッジ日時 | 2025-03-31 17:25:20 |
合計ジャッジ時間 | 1,228 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 |
ソースコード
MOD = 10**9 + 7 n = int(input()) s = input().strip() ans = 0 expected = 'A' for i in range(n, 0, -1): current = s[i-1] if current == expected: continue # Find the other peg which is not current or expected if expected != 'A' and current != 'A': other = 'A' elif expected != 'B' and current != 'B': other = 'B' else: other = 'C' ans += pow(2, i-1, MOD) ans %= MOD expected = other print(ans % MOD)