提出 #55866788


ソースコード 拡げる

n = input()
if n == n[::-1] and '0' not in n:
    print(n)
    exit(0)
n = int(n)
dp = {}
dp[1] = (1,1)
cand = []
mid = [1, ]
for i in range(2, int(n**0.5)+1):
    si = str(i)
    j = int(si[::-1])
    if n % i == 0:
        if n // i % j == 0 and '0' not in si:
            cand.append((i,j))
        if i == j and '0' not in si:
            mid.append(i)
        q = n // i
        if q != i and str(q) == str(q)[::-1] and '0' not in str(q):
            mid.append(q)

def calc(x):
    if x in dp:
        return dp[x]
    dp[x] = None
    for a, b in cand:
        if x % (a * b) == 0 and calc(x // (a * b)):
            dp[x] = (a, b)
            break
    return dp[x]

def get(x, center):
    if x == 1:
        return center
    a, b = dp[x]
    return str(a) + "*" + get(x // a // b, center) + "*" + str(b)

for m in mid:
    if calc(n // m):
        print(get(n // m, str(m)))
        exit(0)
print(-1)

提出情報

提出日時
問題 F - Palindromic Expression
ユーザ pr3pony
言語 Python (CPython 3.11.4)
得点 500
コード長 954 Byte
結果 AC
実行時間 379 ms
メモリ 9280 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 62
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 03_random_3_00.txt, 03_random_3_01.txt, 03_random_3_02.txt, 03_random_3_03.txt, 03_random_3_04.txt, 04_random_4_00.txt, 04_random_4_01.txt, 04_random_4_02.txt, 04_random_4_03.txt, 04_random_4_04.txt, 05_random_5_00.txt, 05_random_5_01.txt, 05_random_5_02.txt, 05_random_5_03.txt, 05_random_5_04.txt, 06_hcn_1_00.txt, 06_hcn_1_01.txt, 06_hcn_1_02.txt, 06_hcn_1_03.txt, 06_hcn_1_04.txt, 06_hcn_1_05.txt, 06_hcn_1_06.txt, 06_hcn_1_07.txt, 06_hcn_1_08.txt, 06_hcn_1_09.txt, 07_hcn_2_00.txt, 07_hcn_2_01.txt, 07_hcn_2_02.txt, 07_hcn_2_03.txt, 07_hcn_2_04.txt, 08_hcn_3_00.txt, 08_hcn_3_01.txt, 08_hcn_3_02.txt, 08_hcn_3_03.txt, 08_hcn_3_04.txt, 08_hcn_3_05.txt, 09_hcn_4_00.txt, 09_hcn_4_01.txt, 09_hcn_4_02.txt, 09_hcn_4_03.txt, 09_hcn_4_04.txt, 10_power_of_2_00.txt, 10_power_of_2_01.txt, 11_corner_00.txt, 11_corner_01.txt, 11_corner_02.txt, 11_corner_03.txt, 11_corner_04.txt, 11_corner_05.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 9 ms 8924 KiB
00_sample_01.txt AC 10 ms 9040 KiB
00_sample_02.txt AC 31 ms 9104 KiB
01_random_1_00.txt AC 52 ms 8868 KiB
01_random_1_01.txt AC 225 ms 8784 KiB
01_random_1_02.txt AC 103 ms 8844 KiB
01_random_1_03.txt AC 276 ms 8840 KiB
01_random_1_04.txt AC 366 ms 8760 KiB
02_random_2_00.txt AC 336 ms 9076 KiB
02_random_2_01.txt AC 311 ms 9216 KiB
02_random_2_02.txt AC 326 ms 9096 KiB
02_random_2_03.txt AC 295 ms 9060 KiB
02_random_2_04.txt AC 340 ms 9108 KiB
03_random_3_00.txt AC 221 ms 8996 KiB
03_random_3_01.txt AC 258 ms 9080 KiB
03_random_3_02.txt AC 340 ms 9016 KiB
03_random_3_03.txt AC 262 ms 9072 KiB
03_random_3_04.txt AC 304 ms 9020 KiB
04_random_4_00.txt AC 376 ms 9064 KiB
04_random_4_01.txt AC 332 ms 8976 KiB
04_random_4_02.txt AC 308 ms 9040 KiB
04_random_4_03.txt AC 308 ms 9008 KiB
04_random_4_04.txt AC 308 ms 8996 KiB
05_random_5_00.txt AC 9 ms 8832 KiB
05_random_5_01.txt AC 9 ms 8928 KiB
05_random_5_02.txt AC 9 ms 8848 KiB
05_random_5_03.txt AC 9 ms 8872 KiB
05_random_5_04.txt AC 9 ms 8868 KiB
06_hcn_1_00.txt AC 129 ms 9212 KiB
06_hcn_1_01.txt AC 145 ms 9148 KiB
06_hcn_1_02.txt AC 156 ms 9168 KiB
06_hcn_1_03.txt AC 161 ms 9084 KiB
06_hcn_1_04.txt AC 193 ms 9136 KiB
06_hcn_1_05.txt AC 216 ms 9280 KiB
06_hcn_1_06.txt AC 225 ms 9200 KiB
06_hcn_1_07.txt AC 275 ms 9048 KiB
06_hcn_1_08.txt AC 312 ms 9228 KiB
06_hcn_1_09.txt AC 377 ms 9116 KiB
07_hcn_2_00.txt AC 133 ms 9096 KiB
07_hcn_2_01.txt AC 194 ms 9028 KiB
07_hcn_2_02.txt AC 214 ms 9096 KiB
07_hcn_2_03.txt AC 259 ms 9068 KiB
07_hcn_2_04.txt AC 279 ms 8960 KiB
08_hcn_3_00.txt AC 234 ms 8892 KiB
08_hcn_3_01.txt AC 279 ms 8828 KiB
08_hcn_3_02.txt AC 283 ms 8852 KiB
08_hcn_3_03.txt AC 351 ms 9196 KiB
08_hcn_3_04.txt AC 348 ms 8828 KiB
08_hcn_3_05.txt AC 373 ms 8804 KiB
09_hcn_4_00.txt AC 176 ms 8764 KiB
09_hcn_4_01.txt AC 215 ms 9148 KiB
09_hcn_4_02.txt AC 246 ms 9020 KiB
09_hcn_4_03.txt AC 304 ms 9064 KiB
09_hcn_4_04.txt AC 346 ms 9108 KiB
10_power_of_2_00.txt AC 204 ms 8992 KiB
10_power_of_2_01.txt AC 278 ms 9104 KiB
11_corner_00.txt AC 12 ms 8896 KiB
11_corner_01.txt AC 10 ms 8904 KiB
11_corner_02.txt AC 9 ms 8996 KiB
11_corner_03.txt AC 9 ms 8964 KiB
11_corner_04.txt AC 9 ms 9008 KiB
11_corner_05.txt AC 379 ms 9052 KiB