結果
問題 |
No.1994 Confusing Name
|
ユーザー |
![]() |
提出日時 | 2022-03-30 21:34:09 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 903 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 462,976 KB |
最終ジャッジ日時 | 2024-11-15 12:37:02 |
合計ジャッジ時間 | 33,104 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 TLE * 8 |
ソースコード
import sys input = sys.stdin.readline class Node: def __init__(self): self.num = 0 self.next = [None] * 27 class Trie: def __init__(self): self.root = Node() def add(self, lis): last = self.root for i in lis: if(last.next[i] is None): last.next[i] = Node() last = last.next[i] last.num += 1 def search(self, lis): last = self.root for i in lis: if(last.next[i] is None): return 0 last = last.next[i] return last.num n = int(input()) user = [] trie = Trie() for i in range(n): s = input().rstrip() l = [ord(c) - ord('a') for c in s] user.append(list(l)) cl = l[:]; cl[0] = 26 trie.add(cl) for j in range(1, len(cl)): cl[j - 1] = l[j - 1] cl[j] = 26 trie.add(cl) for l in user: ans = 0 cl = l[:]; cl[0] = 26 ans += trie.search(cl) - 1 for j in range(1, len(cl)): cl[j - 1] = l[j - 1] cl[j] = 26 ans += trie.search(cl) - 1 print(ans)