complete 2098.py 5052.py 14425*.py 14725.py & add 13505.py

This commit is contained in:
2024-11-25 18:34:48 +09:00
parent 334aa22a28
commit f026c2ef95
6 changed files with 232 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import sys
input = sys.stdin.readline
def is_consist(N: int, S: list) -> bool:
S.sort()
trie = [[0] * 10 for _ in range(155050)]
fin = [0] * 155050
cnt = 0
for s in S:
idx = 0
for c in s:
if fin[idx]:
return False
if trie[idx][int(c)]:
idx = trie[idx][int(c)]
else:
trie[idx][int(c)] = cnt + 1
idx = cnt + 1
cnt += 1
fin[idx] = 1
return True
if __name__ == '__main__':
T = int(input())
for _ in range(T):
N = int(input())
S = [input().rstrip() for _ in range(N)]
print("YES" if is_consist(N, S) else "NO")