結果

問題 No.1617 Palindrome Removal
ユーザー simansiman
提出日時 2021-07-25 07:36:18
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 330 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 18,456 KB
最終ジャッジ日時 2023-09-27 20:36:25
合計ジャッジ時間 5,392 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 221 ms
17,956 KB
testcase_01 AC 221 ms
18,444 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 220 ms
18,212 KB
testcase_05 AC 197 ms
17,720 KB
testcase_06 AC 74 ms
18,412 KB
testcase_07 AC 73 ms
17,140 KB
testcase_08 AC 72 ms
15,292 KB
testcase_09 AC 71 ms
15,200 KB
testcase_10 AC 234 ms
17,880 KB
testcase_11 AC 205 ms
17,644 KB
testcase_12 AC 239 ms
18,404 KB
testcase_13 AC 233 ms
18,456 KB
testcase_14 AC 71 ms
15,040 KB
testcase_15 AC 72 ms
15,096 KB
testcase_16 AC 75 ms
15,340 KB
testcase_17 AC 71 ms
15,232 KB
testcase_18 AC 72 ms
15,136 KB
testcase_19 AC 71 ms
15,100 KB
testcase_20 AC 70 ms
15,096 KB
testcase_21 AC 71 ms
15,088 KB
testcase_22 AC 69 ms
15,028 KB
testcase_23 AC 68 ms
15,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:30: 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
    puts -1
  else
    puts N - 2
  end
end
0