This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
from itertools import permutations
n = int(input())
words = [input() for _ in range(n)]
best = []
for per in permutations(words):
m = []
printer = ''
for i in per:
r = len(printer)
for j in range(len(printer)):
if j > len(i) or printer[j] != i[j]:
r = len(printer) - j
break
m.extend(['-'] * r)
m.extend([j for j in i[-(len(i) - (len(printer) - r)):]])
printer = i
m.append('P')
if len(best) == 0 or len(m) < len(best):
best = m
print(len(best))
for i in best:
print(i)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |