結果

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

ソースコード

diff #
raw source code

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

  def run
    call("")
    return @strs.uniq.size
  end
  
  private

  def call(maked)
    if @s.size == 1
      maked += @s[0]
      @strs << maked
      return
    else
      maked_dup_1 = maked.dup
      first_c = @s.shift
      maked_dup_1 += first_c
      call(maked_dup_1)
      @s.unshift(first_c)

      maked_dup_2 = maked.dup
      last_c = @s.pop
      maked_dup_2 += last_c
      call(maked_dup_2)
      @s.push(last_c)
    end
  end
end

puts Solve.new.run
0