結果
| 問題 |
No.1617 Palindrome Removal
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-22 21:29:21 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 428 bytes |
| コンパイル時間 | 122 ms |
| コンパイル使用メモリ | 6,944 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-17 16:28:38 |
| 合計ジャッジ時間 | 1,411 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
ソースコード
local s = io.read()
local allsame = true
local n = #s
for i = 2, n do
if s:byte(1) ~= s:byte(i) then
allsame = false break
end
end
local pali = true
for i = 1, n do
local j = n + 1 - i
if i < j then
if s:byte(i) ~= s:byte(j) then pali = false break end
else
break
end
end
if allsame then
print(n % 2 == 0 and 0 or -1)
else
if pali then
print(n == 3 and -1 or n - 2)
else
print(n)
end
end