結果

問題 No.1994 Confusing Name
ユーザー MasKoaTSMasKoaTS
提出日時 2022-04-16 12:49:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 851,308 KB
最終ジャッジ日時 2023-08-26 17:31:47
合計ジャッジ時間 8,528 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,460 KB
testcase_01 AC 82 ms
76,096 KB
testcase_02 AC 84 ms
76,236 KB
testcase_03 AC 75 ms
71,472 KB
testcase_04 AC 76 ms
71,176 KB
testcase_05 AC 132 ms
84,900 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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