Submission #55915719
Source Code Expand
Copy
import sys# {1,2,3} -> ... -> {3,2,1}def next_permutation(arr, n):target = -1for i in range(n - 2, -1, -1):if arr[i] < arr[i + 1]:target = ibreakif target < 0:return Falsei = 0while target + i + 1 < n - i - 1:temp = arr[target + 1 + i]arr[target + 1 + i] = arr[n - 1 - i]arr[n - i - 1] = tempi += 1i = target + 1for j in range(target + 1, n):
import sys
# {1,2,3} -> ... -> {3,2,1}
def next_permutation(arr, n):
target = -1
for i in range(n - 2, -1, -1):
if arr[i] < arr[i + 1]:
target = i
break
if target < 0:
return False
i = 0
while target + i + 1 < n - i - 1:
temp = arr[target + 1 + i]
arr[target + 1 + i] = arr[n - 1 - i]
arr[n - i - 1] = temp
i += 1
i = target + 1
for j in range(target + 1, n):
if arr[j] > arr[target]:
i = j
break
temp = arr[i]
arr[i] = arr[target]
arr[target] = temp
return True
N, K = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
S = list(sys.stdin.readline().rstrip())
S = sorted(S)
count = 0
while True:
ok = True
for i in range(K, N + 1):
local_ok = False
for j in range(0, K):
if S[i - K + j] != S[i - 1 - j]:
local_ok = True
break
if not local_ok:
ok = False
break
if ok:
count += 1
if not next_permutation(S, N):
break
print(count)
Submission Info
| Submission Time | |
|---|---|
| Task | C - Avoid K Palindrome 2 |
| User | mikecat |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 300 |
| Code Size | 964 Byte |
| Status | AC |
| Exec Time | 364 ms |
| Memory | 83324 KB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| 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 | 57 ms | 76600 KB |
| example_01.txt | AC | 57 ms | 76428 KB |
| example_02.txt | AC | 128 ms | 82728 KB |
| hand_00.txt | AC | 58 ms | 76504 KB |
| hand_01.txt | AC | 57 ms | 76396 KB |
| hand_02.txt | AC | 364 ms | 82640 KB |
| hand_03.txt | AC | 245 ms | 82744 KB |
| hand_04.txt | AC | 58 ms | 76528 KB |
| hand_05.txt | AC | 108 ms | 83240 KB |
| hand_06.txt | AC | 106 ms | 83092 KB |
| random_00.txt | AC | 57 ms | 76524 KB |
| random_01.txt | AC | 58 ms | 76264 KB |
| random_02.txt | AC | 57 ms | 76268 KB |
| random_03.txt | AC | 58 ms | 76268 KB |
| random_04.txt | AC | 57 ms | 76368 KB |
| random_05.txt | AC | 61 ms | 80844 KB |
| random_06.txt | AC | 79 ms | 81756 KB |
| random_07.txt | AC | 71 ms | 81916 KB |
| random_08.txt | AC | 75 ms | 81980 KB |
| random_09.txt | AC | 86 ms | 83128 KB |
| random_10.txt | AC | 74 ms | 81732 KB |
| random_11.txt | AC | 120 ms | 82840 KB |
| random_12.txt | AC | 89 ms | 83116 KB |
| random_13.txt | AC | 85 ms | 83140 KB |
| random_14.txt | AC | 195 ms | 82944 KB |
| random_15.txt | AC | 98 ms | 82948 KB |
| random_16.txt | AC | 124 ms | 83324 KB |
| random_17.txt | AC | 186 ms | 83052 KB |
| random_18.txt | AC | 58 ms | 76348 KB |
| random_19.txt | AC | 58 ms | 76680 KB |
| random_20.txt | AC | 59 ms | 76232 KB |
| random_21.txt | AC | 57 ms | 76288 KB |
| random_22.txt | AC | 76 ms | 81956 KB |
| random_23.txt | AC | 82 ms | 82548 KB |
| random_24.txt | AC | 78 ms | 81912 KB |
| random_25.txt | AC | 78 ms | 81880 KB |
| random_26.txt | AC | 95 ms | 82912 KB |
| random_27.txt | AC | 94 ms | 83012 KB |