虽然提示给了哈希,但其实直接存子字符串也能过,甚至还稍微快一点……
sub,pwd = {},[] for i in range(int(input())): s = input().strip() pwd.append(s) temp = set() for j in range(len(s)): for k in range(j + 1, len(s) + 1): temp.add(s[j:k]) for tp in temp: try: sub[tp] += 1 except: sub[tp] = 0 print(sum(sub[s] for s in pwd))
虽然提示给了哈希,但其实直接存子字符串也能过,甚至还稍微快一点……