Jae-Kyung Cho LLM Developers who was a Robotics engineer

Baekjoon-1062-가르침

from itertools import combinations

N,K = map(int, input().split(' '))

if K < 5:
    print(0)
    exit()
else:
    K -= 5
    bin_words = []
    for n in range(N):
        word=input()
        for c in ['a','n','t','i','c']:
            word = word.replace(c,'')

        bin_word = [0 for _ in range(26)]
        for c in word:
            bin_word[ord(c)-97] = 1
        bin_words.append(bin_word)
    
    alphabets = list(range(26))
    for c in ['a','n','t','i','c']:
        alphabets.remove(ord(c)-97)
    
    max_count = 0
    for com in combinations(alphabets,K):
        count = 0
        for bin_word in bin_words:
            if sum([bin_word[i] for i in com]) == sum(bin_word):
                count += 1
        if max_count < count:
            max_count = count
    
    print(max_count)
Comments