結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 230 ms
18,456 KB
testcase_02 AC 221 ms
18,192 KB
testcase_03 WA -
testcase_04 AC 235 ms
18,384 KB
testcase_05 AC 204 ms
17,512 KB
testcase_06 AC 77 ms
18,372 KB
testcase_07 AC 75 ms
17,088 KB
testcase_08 AC 74 ms
15,004 KB
testcase_09 AC 73 ms
15,060 KB
testcase_10 AC 235 ms
17,988 KB
testcase_11 AC 219 ms
17,688 KB
testcase_12 AC 245 ms
18,168 KB
testcase_13 AC 242 ms
18,184 KB
testcase_14 AC 73 ms
15,220 KB
testcase_15 AC 75 ms
15,200 KB
testcase_16 AC 73 ms
15,140 KB
testcase_17 AC 74 ms
15,216 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 75 ms
15,124 KB
testcase_21 AC 75 ms
15,108 KB
testcase_22 WA -
testcase_23 AC 74 ms
15,092 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
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 M.even?
  if counter.size == 1
    puts 0
  else
    puts N - 2
  end
else
  if counter.size == 1
    if S[0] == S[M]
      puts -1
    else
      puts N - 2
    end
  else
    puts N - 2
  end
end
0