# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1161443 | browhatt | Type Printer (IOI08_printer) | Pypy 3 | 218 ms | 77452 KiB |
def get_operations(prev, curr):
"""Calculate operations needed to transform prev to curr"""
i = 0
min_len = min(len(prev), len(curr))
# Find common prefix length
while i < min_len and prev[i] == curr[i]:
i += 1
# Generate operations
ops = []
# Backspace operations
ops.extend(['-'] * (len(prev) - i))
# Add new characters
ops.extend(list(curr[i:]))
# Print operation
ops.append('P')
return ops
def solve(words):
n = len(words)
if n == 1:
return list(words[0]) + ['P']
# Sort words to maximize prefix sharing
words.sort()
# Generate operations
operations = []
current = ""
for word in words:
operations.extend(get_operations(current, word))
current = word
return operations
# Read input
n = int(input())
words = [input().strip() for _ in range(n)]
# Get solution
operations = solve(words)
# Print output
print(len(operations))
for op in operations:
print(op)
Compilation message (stdout)
# | 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... |