結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー kotatsugamekotatsugame
提出日時 2022-12-04 00:54:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 217 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-19 11:02:33
合計ジャッジ時間 2,200 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,160 KB
testcase_01 AC 94 ms
12,288 KB
testcase_02 AC 88 ms
12,288 KB
testcase_03 AC 89 ms
12,288 KB
testcase_04 AC 89 ms
12,416 KB
testcase_05 AC 93 ms
12,160 KB
testcase_06 AC 96 ms
12,544 KB
testcase_07 AC 101 ms
13,440 KB
testcase_08 AC 87 ms
12,160 KB
testcase_09 AC 86 ms
12,288 KB
testcase_10 AC 100 ms
13,568 KB
testcase_11 AC 100 ms
13,568 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

n=gets.to_i
s=gets.chomp
a=[0,0,0]
dp=0
s.chars.each{|c|
  c=c.ord-65
  a=[0,1,2].map{|u|[0,1,2].map{|v|
    #v -> u
    a[v]+(c==u ? v==u ? 0 : dp : v==u||v==c ? dp*2+1 : dp+1)
  }.min}
  dp=dp*2+1
}
p a[0].%10**9+7
0