結果
| 問題 |
No.1617 Palindrome Removal
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-07-25 07:37:29 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 265 ms / 2,000 ms |
| コード長 | 416 bytes |
| コンパイル時間 | 43 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 15,104 KB |
| 最終ジャッジ日時 | 2024-07-20 15:10:48 |
| 合計ジャッジ時間 | 4,878 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
コンパイルメッセージ
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
ソースコード
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
siman