結果
| 問題 |
No.765 ukuku 2
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:14:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,490 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 82,084 KB |
| 実行使用メモリ | 83,752 KB |
| 最終ジャッジ日時 | 2025-06-12 19:14:11 |
| 合計ジャッジ時間 | 7,436 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 WA * 19 TLE * 1 -- * 12 |
ソースコード
def main():
import sys
s = sys.stdin.readline().strip()
n = len(s)
if n <= 1:
print(0)
return
# Check if the entire string is a palindrome
is_full_palindrome = True
for i in range(n // 2):
if s[i] != s[n - 1 - i]:
is_full_palindrome = False
break
if is_full_palindrome:
print(n - 1)
return
max_len = 0
# Check for possible max palindrome by removing one character
for i in range(n):
left = i - 1
right = i + 1
current = 0
while left >= 0 and right < n and s[left] == s[right]:
current += 1
left -= 1
right += 1
max_len = max(max_len, 2 * current + 1)
left = i
right = i + 1
current = 0
while left >= 0 and right < n and s[left] == s[right]:
current += 1
left -= 1
right += 1
max_len = max(max_len, 2 * current)
# Now check for removing each character and expanding around i-1 and i+1
for i in range(1, n-1):
if s[i-1] == s[i+1]:
left = i - 1
right = i + 1
current_length = 2
while left > 0 and right < n-1 and s[left-1] == s[right+1]:
current_length += 2
left -= 1
right += 1
max_len = max(max_len, current_length)
print(max_len)
if __name__ == "__main__":
main()
gew1fw