結果
| 問題 |
No.1994 Confusing Name
|
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2022-03-30 21:30:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 851 bytes |
| コンパイル時間 | 304 ms |
| コンパイル使用メモリ | 82,068 KB |
| 実行使用メモリ | 813,600 KB |
| 最終ジャッジ日時 | 2024-11-15 12:31:23 |
| 合計ジャッジ時間 | 37,783 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 15 TLE * 10 MLE * 3 |
ソースコード
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 = [[] for _ in [0] * n]
trie = Trie()
for i in range(n):
s = input().rstrip()
l = [ord(c) - ord('a') for c in s]
cl = l[:]; cl[0] = 26
trie.add(cl)
user[i].append(list(cl))
for j in range(1, len(cl)):
cl[j - 1] = l[j - 1]
cl[j] = 26
trie.add(cl)
user[i].append(list(cl))
for ll in user:
ans = 0
for l in ll:
ans += trie.search(l) - 1
print(ans)
MasKoaTS