公式
B - Invalid Vote 解説 by en_translator
Original proposer: vwxyz
Decide which candidate receives each ballot (or whether it is invalid).
If there is a candidate with a matching candidate name, that candidate receives the ballot.
Otherwise, construct an array. Enumerate the candidates, and append them when modifying one character yields that name. Finally, if the array has a length \(1\), that candidate receives one vote.
Otherwise, the ballot is invalid.
To determine if modifying one character makes it match, count the positions \(k\) for which the two names differ at the \(k\)-th character.
Beware of cases where \(S_i\) and \(T_j\) has different lengths.
Sample code in Python
N,M=map(int,input().split())
S=[input() for i in range(N)]
T=[input() for j in range(M)]
ans_lst=[0]*N
for j in range(M):
if T[j] in S:
ans_lst[S.index(T[j])]+=1
else:
I=[]
for i in range(N):
if len(S[i])==len(T[j]) and sum(s!=t for s,t in zip(S[i],T[j]))==1:
I.append(i)
if len(I)==1:
ans_lst[I[0]]+=1
print(*ans_lst,sep="\n")