파이썬으로 구현 코테 준비하기 3 Problems

froajnzd·2024년 4월 8일
0

python

목록 보기
6/11

구현 문제 풀이

💙 백준 골드4 월드컵

문제번호언어메모리시간
6987Python 331120 KB40 ms
  • 라운드별로 전팀이 이겼을 경우, 비겼을 경우, 후팀이 이겼을 경우를 탐색하면서
    마지막 라운드가 되었을 때, 입력으로 받았던 리스트가 ALL 0이 된다면 가능함
  • 라운드는 총 15개가 있음
  • 불가능한 결과일 경우, 15라운드까지 안갈 수도 있기 때문에, 초기 값은 False로 설정함
  • 만약, 15라운드까지 간 경우, 매 라운드마다 수정한 경기판이 ALL 0이 되어야 함
# 1:2 / 1:3 / 1:4 / 1:5 / 1:6
# 2:3 / 2:4 / 2:5 / 2:6
# 3:4 / 3:5 / 3:6
# 4:5 / 4:6
# 5:6
def combination(lst, cnt):
    res = []
    def combi(c, index):
        if len(c) == cnt:
            res.append(c)
            return
        for idx, data in enumerate(lst):
            if idx > index:
                combi(c+[data], idx)
    combi([], -1)
    return res

def dfs(round):
    global result
    if round == 15:
        result = True
        for asdf in winl:
            if asdf != [0,0,0]:
                result = False
        return

    t1, t2 = game[round]
    for x, y in ((0, 2), (1, 1), (2, 0)):
        if winl[t1][x] > 0 and winl[t2][y] > 0:
            winl[t1][x] -= 1
            winl[t2][y] -= 1
            dfs(round + 1)
            winl[t1][x] += 1
            winl[t2][y] += 1


answer = []
team = [i for i in range(6)]
game = combination(team , 2)
for i in range(4):
    result = False
    wcup = list(map(int, input().strip().split()))
    winl = [wcup[i:i+3] for i in range(0, 18, 3)]

    dfs(0)

    if result:
        print(1)
    else:
        print(0)

🧡 백준 골드1 구슬 탈출2

문제번호언어메모리시간
13460Python 3KBms
profile
Hi I'm 열쯔엉

0개의 댓글