https://www.acmicpc.net/problem/2607
from sys import stdin
from collections import defaultdict
input = stdin.readline
n = int(input())
k = input().rstrip()
ans = 0
k_dict = defaultdict(int)
for i in k:
k_dict[i] += 1
len_k = len(k)
for i in range(n - 1):
t = input().rstrip()
len_t = len(t)
if len_t > len_k + 1 or len_t < len_k - 1:
continue
t_dict = defaultdict(int)
for i in t:
t_dict[i] += 1
tmp = [0, 0, 0] # -1,1,2+
for j in k_dict.keys():
t_dict[j] -= k_dict[j]
for j in t_dict.keys():
if t_dict[j]:
if t_dict[j] == 1:
tmp[1] += 1
elif t_dict[j] == -1:
tmp[0] += 1
else:
tmp[2] += 1
if tmp[0] > 1 or tmp[1] > 1 or tmp[2]:
continue
ans += 1
print(ans)
채점결과 : 60ms
채점 결과 : 34052KB
N = int(input())
word = list(input())
result_cnt = 0
for i in range(N-1):
cnt = 0
compare = word[:]
similar_word = input()
for j in similar_word:
if j in compare:
compare.remove(j)
else:
cnt += 1
if cnt < 2 and len(compare) < 2:
result_cnt += 1
print(result_cnt)