n = int(input())
def compare(a,b):
sus = 0
for i in range(min(len(a),len(b))):
if a[i]==b[i]:
sus += 1
else:
break
return sus
words = dict()
for i in range(n):
words[input()] = 0
maxi = ""
for i in words:
if len(i) > len(maxi):
maxi = i
suswords = dict()
for i in words:
words[i] = compare(i, maxi)
lis = [i for i in words]
lis.sort(key=lambda x: (words[x], x))
ans = 1
cur = []
for i in range(len(lis)-1):
for j in lis[i][len(cur):]:
cur.append(j)
ans += 1
ans += 1
for i in lis[i][compare(lis[i], lis[i+1]):][::-1]:
ans += 1
cur.pop()
for j in lis[-1][len(cur):]:
ans += 1
print(ans)
cur = []
for i in range(len(lis)-1):
for j in lis[i][len(cur):]:
cur.append(j)
print(j)
print("P")
for i in lis[i][compare(lis[i], lis[i+1]):][::-1]:
print("-")
cur.pop()
for j in lis[-1][len(cur):]:
print(j)
print("P")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
18200 KB |
Output is correct |
2 |
Correct |
39 ms |
18228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18260 KB |
Output is correct |
2 |
Correct |
43 ms |
18220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
18192 KB |
Output is correct |
2 |
Correct |
44 ms |
18140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
18180 KB |
Output is correct |
2 |
Correct |
40 ms |
18196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
19616 KB |
Output is correct |
2 |
Correct |
124 ms |
25516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
26344 KB |
Output is correct |
2 |
Correct |
148 ms |
26504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
207 ms |
28208 KB |
Output is correct |
2 |
Correct |
327 ms |
28324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
307 ms |
28132 KB |
Output is correct |
2 |
Correct |
264 ms |
28304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
29412 KB |
Output is correct |
2 |
Correct |
587 ms |
30380 KB |
Output is correct |
3 |
Correct |
422 ms |
30456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
418 ms |
30000 KB |
Output is correct |
2 |
Correct |
644 ms |
32428 KB |
Output is correct |
3 |
Correct |
502 ms |
31740 KB |
Output is correct |
4 |
Correct |
557 ms |
32648 KB |
Output is correct |