Submission #64101268
Source Code Expand
Copy
def shortest_palindrome(S):def contains_palindrome_with_last_char(S):last_char = S[-1]n = len(S)for i in range(n):substring = S[i:]if substring == substring[::-1]:if last_char in substring:return True, ireturn False, -1found, start_index = contains_palindrome_with_last_char(S)if found:return S[:start_index] + S[::-1]else:rev_S = S[::-1]return rev_S + S[1:]S = input()print(shortest_palindrome(S))
def shortest_palindrome(S):
def contains_palindrome_with_last_char(S):
last_char = S[-1]
n = len(S)
for i in range(n):
substring = S[i:]
if substring == substring[::-1]:
if last_char in substring:
return True, i
return False, -1
found, start_index = contains_palindrome_with_last_char(S)
if found:
return S[:start_index] + S[::-1]
else:
rev_S = S[::-1]
return rev_S + S[1:]
S = input()
print(shortest_palindrome(S))
Submission Info
| Submission Time | |
|---|---|
| Task | F - ABCBA |
| User | practicejoi |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 580 Byte |
| Status | TLE |
| Exec Time | 2226 ms |
| Memory | 300452 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 59 ms | 76780 KiB |
| sample_02.txt | AC | 59 ms | 76720 KiB |
| sample_03.txt | AC | 58 ms | 76504 KiB |
| test_01.txt | AC | 58 ms | 76468 KiB |
| test_02.txt | AC | 59 ms | 76520 KiB |
| test_03.txt | AC | 59 ms | 76328 KiB |
| test_04.txt | AC | 58 ms | 76624 KiB |
| test_05.txt | AC | 59 ms | 76332 KiB |
| test_06.txt | AC | 58 ms | 76444 KiB |
| test_07.txt | AC | 59 ms | 76512 KiB |
| test_08.txt | AC | 58 ms | 76724 KiB |
| test_09.txt | AC | 59 ms | 76312 KiB |
| test_10.txt | TLE | 2226 ms | 300380 KiB |
| test_11.txt | TLE | 2225 ms | 300116 KiB |
| test_12.txt | TLE | 2226 ms | 300220 KiB |
| test_13.txt | TLE | 2225 ms | 300452 KiB |
| test_14.txt | TLE | 2226 ms | 300244 KiB |
| test_15.txt | AC | 65 ms | 80284 KiB |
| test_16.txt | TLE | 2226 ms | 300088 KiB |
| test_17.txt | TLE | 2226 ms | 300172 KiB |
| test_18.txt | TLE | 2226 ms | 300092 KiB |
| test_19.txt | TLE | 2225 ms | 300164 KiB |
| test_20.txt | AC | 65 ms | 80084 KiB |
| test_21.txt | TLE | 2226 ms | 300252 KiB |
| test_22.txt | TLE | 2226 ms | 300368 KiB |
| test_23.txt | TLE | 2225 ms | 300252 KiB |
| test_24.txt | TLE | 2226 ms | 300448 KiB |
| test_25.txt | AC | 65 ms | 79876 KiB |
| test_26.txt | TLE | 2225 ms | 300364 KiB |
| test_27.txt | TLE | 2224 ms | 300164 KiB |
| test_28.txt | TLE | 2225 ms | 300092 KiB |
| test_29.txt | TLE | 2225 ms | 300448 KiB |
| test_30.txt | AC | 64 ms | 80032 KiB |
| test_31.txt | TLE | 2225 ms | 300316 KiB |
| test_32.txt | TLE | 2225 ms | 300252 KiB |
| test_33.txt | TLE | 2225 ms | 300088 KiB |