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 |
1 |
Correct |
13 ms |
2900 KB |
Output is correct |
2 |
Correct |
15 ms |
2916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
823 ms |
2916 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
2900 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
907 ms |
2900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
2920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
2900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
3256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
4288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
4260 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1085 ms |
12020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
38 ms |
5708 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |