Skip to content
Open
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
30 changes: 30 additions & 0 deletions MIMO/15686.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
from itertools import combinations

N,M = map(int, sys.stdin.readline().split())
board = []
for i in range(N):
a = list(map(int, sys.stdin.readline().split()))
board.append(a)
chicken = []
house = []
answer = []
for i in range(N):
for j in range(N):
if board[i][j] == 2:
chicken.append([i,j])
elif board[i][j] == 1:
house.append([i,j])
allcount = list(combinations(chicken,M))
for i in range(len(allcount)):
chickendistance = 0
housedistance = [9999 for _ in range(len(house))]
for j in range(len(allcount[i])):
x = allcount[i][j][0]
y = allcount[i][j][1]
for k in range(len(house)):
tmp = abs(house[k][0] - x) + abs(house[k][1] - y)
if housedistance[k] > tmp:
housedistance[k] = tmp
answer.append(sum(housedistance))
print(min(answer))