結果

問題 No.1994 Confusing Name
コンテスト
ユーザー MasKoaTS
提出日時 2022-04-16 12:49:50
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 904 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 241 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 1,077,888 KB
最終ジャッジ日時 2026-05-31 09:36:48
合計ジャッジ時間 5,063 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 6 MLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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