結果

問題 No.1617 Palindrome Removal
ユーザー simansiman
提出日時 2021-07-25 07:37:29
言語 Ruby
(3.3.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 11,424 KB
実行使用メモリ 18,504 KB
最終ジャッジ日時 2023-09-27 20:37:29
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
18,152 KB
testcase_01 AC 253 ms
18,256 KB
testcase_02 AC 242 ms
18,068 KB
testcase_03 AC 240 ms
18,160 KB
testcase_04 AC 250 ms
18,348 KB
testcase_05 AC 217 ms
17,572 KB
testcase_06 AC 84 ms
18,176 KB
testcase_07 AC 84 ms
16,932 KB
testcase_08 AC 81 ms
15,248 KB
testcase_09 AC 82 ms
15,244 KB
testcase_10 AC 252 ms
17,864 KB
testcase_11 AC 229 ms
17,720 KB
testcase_12 AC 265 ms
18,504 KB
testcase_13 AC 270 ms
18,224 KB
testcase_14 AC 81 ms
15,036 KB
testcase_15 AC 81 ms
15,284 KB
testcase_16 AC 81 ms
15,036 KB
testcase_17 AC 81 ms
15,260 KB
testcase_18 AC 82 ms
15,036 KB
testcase_19 AC 83 ms
15,100 KB
testcase_20 AC 82 ms
15,296 KB
testcase_21 AC 83 ms
15,044 KB
testcase_22 AC 82 ms
15,272 KB
testcase_23 AC 81 ms
14,984 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:35: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

S = gets.chomp
N = S.size
M = N / 2

if S != S.reverse
  puts N
  exit
end

if S.size == 1
  puts -1
  exit
end

counter = Hash.new(0)

M.times do |i|
  s = S[i]
  counter[s] += 1
end

if N.even?
  if counter.size == 1
    puts 0
  else
    puts N - 2
  end
else
  if counter.size == 1
    if S[0] == S[M]
      puts -1
    elsif N > 3
      puts N - 2
    else
      puts -1
    end
  else
    puts N - 2
  end
end
0