結果

問題 No.1994 Confusing Name
コンテスト
ユーザー MasKoaTS
提出日時 2022-03-30 21:34:09
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,548 ms / 2,000 ms
コード長 903 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 154 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 467,328 KB
最終ジャッジ日時 2026-05-10 11:51:29
合計ジャッジ時間 18,898 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0