結果

問題 No.52 よくある文字列の問題
コンテスト
ユーザー DialBird
提出日時 2017-02-14 21:44:02
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 540 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 51 ms
コンパイル使用メモリ 9,088 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2026-04-10 11:14:32
合計ジャッジ時間 1,364 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

class Solve
  def initialize
    @s = gets.chomp.split('')
    @results = []
  end

  def run
    call(@s, "")
    return @results.uniq.size
  end

  private

  def call(rest_str, maked_str)
    if rest_str.size == 1
      maked_str += rest_str[0]
      @results << maked_str
      return
    else
      new_str_1 = maked_str.dup
      new_str_1 += rest_str[0]
      call(rest_str[1..-1], new_str_1)
      new_str_2 = maked_str.dup
      new_str_2 += rest_str[-1]
      call(rest_str[0..-2], new_str_2)
    end
  end
end

puts Solve.new.run
0