結果
| 問題 |
No.273 回文分解
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-10 16:20:01 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 364 bytes |
| コンパイル時間 | 30 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-12-23 13:20:22 |
| 合計ジャッジ時間 | 3,738 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 7 |
コンパイルメッセージ
Syntax OK
ソースコード
s = gets.chomp
n = s.length
def is_valid?(s, i, j)
len = i - j
return true if 1 == len
center = (i + j) / 2
if 0 == (len % 2)
return s[i..(center-1)] == s[center..(j-1)].reverse
end
s[i..(center-1)] == s[(center+1)..(j-1)].reverse
end
ans = [1]
1.upto(n-1) do |i|
i.upto(n) do |j|
ans << (j-i) if is_valid?(s, i, j)
end
end
puts ans.max