3502. 密码碰撞

CCXXXI_

虽然提示给了哈希,但其实直接存子字符串也能过,甚至还稍微快一点……

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))
你当前正在回复 博客/题目
存在问题!