[AtCoder]ABC 249 C-Just K

photo of woman posing during golden hour AtCoder
Photo by Eternal Happiness on Pexels.com

問題

問題キャプチャ。

方針

全検索でよい。Bit全検索でもpythonのitertools libraryのcombinationsでも。

解答

#input
from collections import Counter
from itertools import combinations

n, k = map(int, input().split())
s = [[] for _ in range(n)]
for i in range(n):
    s[i] = input()

#output
answer = 0
for i in range(1, n+1):
    for j in combinations([p for p in range(n)], i):
        temp = ""
        M = 0
        for x in j:
            temp += s[x]
            temp2 = Counter(temp)
        for y in temp2.values():
            if y == k:
                M += 1
        answer = max(answer, M)

print(answer)

提出結果

Submission #31482119 - Monoxer Programming Contest 2022(AtCoder Beginner Contest 249)
AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.

感想

ちょっとcodeがpoorな気が。時間も結構かかっている。

コメント

タイトルとURLをコピーしました