2022 KAKAO BLIND RECRUITMENT - 양궁대회 (Level 2)

 

https://programmers.co.kr/learn/courses/30/lessons/92342


Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from itertools import combinations

def solution(n, info):
    max_score_diff = 0
    scores         = {0: 0}
    targets        = [(score, info[10-score]+1, 2 if info[10-score]>0 else 1) for score in range(10, 0, -1)]
    for n_targets in range(1, n+1):
        for comb in combinations(targets, n_targets):
            comb = list(comb)
            n_shots = sum(n_scores for score, n_scores, bonus in comb)
            if n_shots > n:
                continue
            elif n_shots < n:
                comb.append((0, n-n_shots, 1))
            scores_cur = dict([(score, n_scores) for score, n_scores, bonus in comb])

            score1, score2 = 0, 0
            info_cur = [scores_cur.get(10-i, 0) for i in range(11)]
            for score, (shot1, shot2) in enumerate(zip(info, info_cur)):
                if (shot1 >= shot2) and (shot1 > 0):
                    score1 += 10-score
                elif (shot1 < shot2) and (shot2 > 0):
                    score2 += 10-score

            score_diff_cur = score2 - score1
            if score_diff_cur > max_score_diff:
                max_score_diff = score_diff_cur
                scores = dict([(score, n_scores) for score, n_scores, bonus in comb])
                info_answer = info_cur
            elif score_diff_cur == max_score_diff:
                min_score = min(min(scores), min(scores_cur))
                if scores.get(min_score, 0) < scores_cur.get(min_score, 0):
                    scores = scores_cur
                    info_answer = info_cur

    # print(info_answer)
    if max_score_diff <= 0:
        return [-1]
    return info_answer

Complexity

$O(n!)$