Submission #626445

# Submission time Handle Problem Language Result Execution time Memory
626445 2022-08-11T12:56:03 Z hspark8494 Type Printer (IOI08_printer) Python 3
30 / 100
1000 ms 67632 KB
class trie:
    def __init__(self, parent):
        self.data = {}
        self.parent = parent
        self.dept = 0
        self.end = False

words = []

tries = trie(None)
n = int(input())
for _ in range(n):
    word = input()
    words.append(word)
    curr = tries
    for w in word:
        if not w in curr.data:
            curr.data[w] = trie(curr)
        curr = curr.data[w]
        p = curr.parent
        while p:
            p.dept+=1
            p = p.parent
    else:
        curr.end = True


def dfs_trie(curr:trie, result):
    global n
    if curr.end:
        result.append("P")
        n -= 1
    for c in sorted(curr.data.keys(), key=lambda x:curr.data[x].dept):
        result.append(c)
        dfs_trie(curr.data[c], result)
    if n>0:
        result.append("-")
result = []
dfs_trie(tries, result)

print(len(result))
print("\n".join(result))
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2900 KB Output is correct
2 Correct 13 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2848 KB Output is correct
2 Correct 13 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2900 KB Output is correct
2 Correct 16 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 5632 KB Output is correct
2 Incorrect 61 ms 6372 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 13236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 583 ms 29436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 67632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 54548 KB Time limit exceeded
2 Halted 0 ms 0 KB -