Submission #55776424


Source Code Expand

import itertools
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

n, k = map(int, input().split())
s = list(input().rstrip())
ans = 0
for p in itertools.permutations(s, n):
    ok = 1
    for i in range(n - k + 1):
        f = 0
        for j in range(k >> 1):
            if p[i + j] ^ p[i + k - j - 1]:
                f = 1
                break
        if not f:
            ok = 0
            break
    if ok:
        ans += 1
cnt = [0] * 26
for i in s:
    cnt[i - 97] += 1
fact = [1] * (n + 1)
for i in range(2, n + 1):
    fact[i] = i * fact[i - 1]
for i in cnt:
    ans //= fact[i]
print(ans)

Submission Info

Submission Time
Task C - Avoid K Palindrome 2
User misorin
Language Python (PyPy 3.10-v7.3.12)
Score 300
Code Size 661 Byte
Status AC
Exec Time 313 ms
Memory 82988 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 38
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt
Case Name Status Exec Time Memory
example_00.txt AC 56 ms 76472 KiB
example_01.txt AC 55 ms 76748 KiB
example_02.txt AC 243 ms 82788 KiB
hand_00.txt AC 162 ms 82500 KiB
hand_01.txt AC 258 ms 82784 KiB
hand_02.txt AC 252 ms 82272 KiB
hand_03.txt AC 161 ms 82636 KiB
hand_04.txt AC 272 ms 82680 KiB
hand_05.txt AC 234 ms 82568 KiB
hand_06.txt AC 235 ms 82684 KiB
random_00.txt AC 159 ms 82440 KiB
random_01.txt AC 160 ms 82588 KiB
random_02.txt AC 176 ms 82880 KiB
random_03.txt AC 81 ms 82520 KiB
random_04.txt AC 75 ms 82364 KiB
random_05.txt AC 186 ms 82592 KiB
random_06.txt AC 79 ms 82844 KiB
random_07.txt AC 206 ms 82780 KiB
random_08.txt AC 83 ms 82664 KiB
random_09.txt AC 85 ms 82708 KiB
random_10.txt AC 79 ms 82684 KiB
random_11.txt AC 237 ms 82680 KiB
random_12.txt AC 83 ms 82644 KiB
random_13.txt AC 81 ms 82704 KiB
random_14.txt AC 313 ms 82460 KiB
random_15.txt AC 86 ms 82404 KiB
random_16.txt AC 298 ms 82568 KiB
random_17.txt AC 244 ms 82984 KiB
random_18.txt AC 60 ms 81412 KiB
random_19.txt AC 201 ms 82624 KiB
random_20.txt AC 307 ms 82716 KiB
random_21.txt AC 291 ms 82708 KiB
random_22.txt AC 283 ms 82988 KiB
random_23.txt AC 287 ms 82616 KiB
random_24.txt AC 64 ms 81840 KiB
random_25.txt AC 68 ms 81684 KiB
random_26.txt AC 234 ms 82664 KiB
random_27.txt AC 228 ms 82916 KiB