Skip to content

[박희경] 125차 라이브 코테 제출 #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions live12/test125/문제1/박희경.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
인접하는 집의 색상이 같지 않다.
dp
"""
import sys

input = sys.stdin.readline

cost = []
n = int(input())
for _ in range(n):
cost.append(list(map(int, input().split())))


dp = cost.copy()


for i in range(1, n):



"""
3
26 40 83
49 60 57
13 89 99
"""
42 changes: 42 additions & 0 deletions live12/test125/문제2/박희경.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
import copy

input = sys.stdin.readline


def flip(coins, line):
for x, y in line:
coins[x][y] = 'T' if coins[x][y] == 'H' else 'H'


def dfs(coins, lines, idx, count, min_count):
flat = sum(coins, [])
if flat.count('T') == 9 or flat.count('H') == 9:
return min(count, min_count)
if idx == len(lines): # 더이상 뒤집을 줄이 없을 때
return min_count

result = dfs(copy.deepcopy(coins), lines, idx+1, count, min_count) # 뒤집지 않고 다음 줄로 넘기는 경우

# 뒤집고 넘기는 경우
flipped = copy.deepcopy(coins)
flip(flipped, lines[idx])
result = min(result, dfs(flipped, lines, idx+1, count+1, min_count))

return result

row_lines = [[(i, j) for j in range(3)] for i in range(3)]
col_lines = [[(j, i) for j in range(3)] for i in range(3)]
diag_lines = [[(i, i) for i in range(3)], [(i, 2 - i) for i in range(3)]]
lines = row_lines + col_lines + diag_lines # 나올 수 있는 모든 경우의 수

t = int(input())
for _ in range(t):
coins = []
for _ in range(3):
coins.append(list(input().split()))
res = dfs(coins, lines, 0, 0, float('inf'))
if res != float('inf'):
print(res)
else:
print(-1)