Submission #64096532
Source Code Expand
Copy
def shortest_palindrome(s):rev_s = s[::-1]for i in range(len(s)):if s[: len(s) - i] == rev_s[i:]:return s + rev_s[len(s) - i :]s = input()rev_s = s[::-1]a = []i = 0while i < len(rev_s):j = iwhile j < len(rev_s) and rev_s[i] == rev_s[j]:j += 1a.append((rev_s[i], j - i))i = jb = a[0][1]c = len(shortest_palindrome(s))d = len((s[: len(s) - b] + rev_s))if c < d:
def shortest_palindrome(s):
rev_s = s[::-1]
for i in range(len(s)):
if s[: len(s) - i] == rev_s[i:]:
return s + rev_s[len(s) - i :]
s = input()
rev_s = s[::-1]
a = []
i = 0
while i < len(rev_s):
j = i
while j < len(rev_s) and rev_s[i] == rev_s[j]:
j += 1
a.append((rev_s[i], j - i))
i = j
b = a[0][1]
c = len(shortest_palindrome(s))
d = len((s[: len(s) - b] + rev_s))
if c < d:
print(shortest_palindrome(s))
else:
print(s[: len(s) - b] + rev_s)
Submission Info
| Submission Time | |
|---|---|
| Task | F - ABCBA |
| User | practicejoi |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 0 |
| Code Size | 529 Byte |
| Status | WA |
| Exec Time | 2223 ms |
| Memory | 306880 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 | 53 ms | 76232 KiB |
| sample_02.txt | AC | 53 ms | 76704 KiB |
| sample_03.txt | AC | 53 ms | 76244 KiB |
| test_01.txt | AC | 53 ms | 76432 KiB |
| test_02.txt | AC | 54 ms | 76276 KiB |
| test_03.txt | AC | 53 ms | 76428 KiB |
| test_04.txt | AC | 53 ms | 76412 KiB |
| test_05.txt | AC | 53 ms | 76552 KiB |
| test_06.txt | AC | 53 ms | 76456 KiB |
| test_07.txt | AC | 53 ms | 76328 KiB |
| test_08.txt | AC | 53 ms | 76360 KiB |
| test_09.txt | WA | 53 ms | 76424 KiB |
| test_10.txt | TLE | 2223 ms | 306640 KiB |
| test_11.txt | TLE | 2223 ms | 306500 KiB |
| test_12.txt | TLE | 2223 ms | 306880 KiB |
| test_13.txt | TLE | 2223 ms | 306620 KiB |
| test_14.txt | TLE | 2223 ms | 306644 KiB |
| test_15.txt | AC | 132 ms | 145392 KiB |
| test_16.txt | TLE | 2223 ms | 306848 KiB |
| test_17.txt | TLE | 2223 ms | 306280 KiB |
| test_18.txt | TLE | 2223 ms | 306552 KiB |
| test_19.txt | TLE | 2223 ms | 306600 KiB |
| test_20.txt | AC | 133 ms | 145572 KiB |
| test_21.txt | TLE | 2223 ms | 306260 KiB |
| test_22.txt | TLE | 2223 ms | 306700 KiB |
| test_23.txt | TLE | 2223 ms | 306468 KiB |
| test_24.txt | TLE | 2223 ms | 306812 KiB |
| test_25.txt | AC | 132 ms | 145328 KiB |
| test_26.txt | TLE | 2223 ms | 306504 KiB |
| test_27.txt | TLE | 2223 ms | 306444 KiB |
| test_28.txt | TLE | 2223 ms | 306508 KiB |
| test_29.txt | TLE | 2223 ms | 306872 KiB |
| test_30.txt | AC | 133 ms | 145080 KiB |
| test_31.txt | TLE | 2223 ms | 306240 KiB |
| test_32.txt | TLE | 2223 ms | 306548 KiB |
| test_33.txt | TLE | 2223 ms | 306420 KiB |