結果
問題 |
No.1994 Confusing Name
|
ユーザー |
![]() |
提出日時 | 2022-04-16 12:49:50 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 904 bytes |
コンパイル時間 | 482 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 1,140,864 KB |
最終ジャッジ日時 | 2024-12-25 16:42:56 |
合計ジャッジ時間 | 55,734 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 MLE * 1 |
other | AC * 1 WA * 5 TLE * 6 MLE * 16 |
ソースコード
import sys input = sys.stdin.readline class Node: def __init__(self): self.num = 0 self.next = [None] * 2 class BinaryTrie: def __init__(self, d): self.root = Node() self.d = d def add(self, n): last = self.root for _ in [0] * self.d: i = n & 1 if(last.next[i] is None): last.next[i] = Node() last = last.next[i] n >>= 1 last.num += 1 def search(self, n): last = self.root for _ in [0] * self.d: i = n & 1 if(last.next[i] is None): return 0 last = last.next[i] n >>= 1 return last.num n = int(input()) d = 50 user = [] trie = BinaryTrie(d) for i in range(n): s = input().rstrip() lis = [0] * len(s) for i in range(len(s)): for j in range(len(s)): k = 26 if(i == j) else ord(s[j]) - ord('a') lis[i] = lis[i] * 27 + k trie.add(lis[i]) user.append(lis) for l in user: ans = 0 for t in l: ans += trie.search(t) - 1 print(ans)