結果
| 問題 |
No.1994 Confusing Name
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2024-08-25 20:37:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 711 bytes |
| コンパイル時間 | 408 ms |
| コンパイル使用メモリ | 82,040 KB |
| 実行使用メモリ | 122,028 KB |
| 最終ジャッジ日時 | 2024-08-25 20:37:10 |
| 合計ジャッジ時間 | 6,796 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 18 |
ソースコード
n=int(input())
ss=[]
d={}
M=1000000007
from random import randrange
B=randrange(M)
P=[1]
for i in range(1,10):
P+=[P[-1]*B%M]
for i in range(n):
s=input()
h=0
for j in range(len(s)):
h+=ord(s[j])*P[j]
h%=M
if h not in d:
d[h]=0
d[h]+=1
for j in range(len(s)):
h-=ord(s[j])*P[j]
h+=ord("?")*P[j]
h%=M
if h not in d:
d[h]=0
d[h]+=1
h-=ord("?")*P[j]
h+=ord(s[j])*P[j]
h%=M
ss+=[s]
for i in range(n):
s=ss[i]
h=0
for j in range(len(s)):
h+=ord(s[j])*P[j]
h%=M
c=0
for j in range(len(s)):
h-=ord(s[j])*P[j]
h+=ord("?")*P[j]
h%=M
c+=d[h]
h-=ord("?")*P[j]
h+=ord(s[j])*P[j]
h%=M
c-=d[h]*len(s)
print(c)
sasa8uyauya