結果

問題 No.1994 Confusing Name
ユーザー FromBooska
提出日時 2023-06-19 22:04:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 142,196 KB
最終ジャッジ日時 2024-06-27 09:56:43
合計ジャッジ時間 8,599 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

# 公式解説による二重ループを避ける方法
# それぞれの名前の一字替えをdefaultdictに入れて数え上げる

N = int(input())
from collections import defaultdict
dic = defaultdict(int)
S = []
for i in range(N):
    temp = input()
    S.append(temp)
    for j in range(len(temp)):
        s = temp[:j] + '?' + temp[j+1:]
        dic[s] += 1

#print(dic)
        
for s in S:
    ans = 0
    for j in range(len(s)):
        temp = s[:j] + '?' + s[j+1:]
        ans += max(0, dic[temp]-1)
        # 自らの変形分である1を引く必要ある
    print(ans)
0