문제 링크

문제 설명

예시

[input]
3
acornistnt
peanutbomb
constraint

[output]
1

[input]
2
oneplustwo
ninemodsix

[output]
0

[input]
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

[output]
4

사고의 흐름

모범답안

1. 여기를 누르면 답이 보입니다
from collections import Counter

def compare(left, right):
  for k in left.keys():
    if right.get(k) is None or right[k] != left[k]:
      return False
    return True
  

n = int(input())
arr = []
count = 0
history = [0]*n
for _ in range(n):
  s = input()
  c = Counter(s)
  for i in range(len(arr)-1, -1, -1):
    if compare(c, arr[i]) is True:
      history[len(arr)] = history[i]+1
      count += history[len(arr)]
      break
  arr.append(c)
print(count)
2. 여기를 누르면 답이 보입니다