結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー kotatsugamekotatsugame
提出日時 2022-12-04 00:54:46
言語 Ruby
(3.2.2)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 217 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 11,204 KB
実行使用メモリ 15,908 KB
最終ジャッジ日時 2023-08-01 11:30:19
合計ジャッジ時間 2,576 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,088 KB
testcase_01 AC 79 ms
15,168 KB
testcase_02 AC 79 ms
15,288 KB
testcase_03 AC 79 ms
15,160 KB
testcase_04 AC 80 ms
15,156 KB
testcase_05 AC 80 ms
15,036 KB
testcase_06 AC 82 ms
15,388 KB
testcase_07 AC 88 ms
15,736 KB
testcase_08 AC 78 ms
15,080 KB
testcase_09 AC 77 ms
15,088 KB
testcase_10 AC 88 ms
15,808 KB
testcase_11 AC 88 ms
15,908 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