McDonald’s seasonal menu McRib was not very tasty.
Codeforces Round #992 (Div.2) Editorial
:thinking_face:
I can’t understand or replicate the solution, but the way they construct a permutation might be worth remembering.
Instead of generating all permutations n!
, the solution
picks two positions (the leftmost/rightmost blank spaces) for each
number so that only 2^n
permutations need to be
checked.
The problem can be rephrased as counting how many different ways we
can insert a partition between n
identical blocks.
For example, consider the number 5 expressed as:
5 = 1 + 1 + 1 + 1 + 1
Some of possible ways to place a single partition are:
for _ in range(int(input())):
print(int(input()) - 1)
for _ in range(int(input())):
list[str] = list(input())
s: list[str] = s[::-1]
srev: for i in range(len(s)):
if srev[i] == "p":
= "q"
srev[i] elif srev[i] == "q":
= "p"
srev[i] print("".join(srev))
_ lb
TODO: