-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
from itertools import combinations | ||
|
||
def input(): return sys.stdin.readline().rstrip() | ||
|
||
N, M = map(int, input().split()) | ||
house = [[] for _ in range(N)] | ||
chicken_house = [] | ||
chicken_dis = [[9999 for _ in range(N)] for _ in range(N)] | ||
result = 99999 | ||
|
||
for i in range(N): | ||
house[i].extend(map(int, input().split())) | ||
|
||
for r in range(N): | ||
for c in range(N): | ||
if house[r][c] == 2: | ||
chicken_house.append((r, c)) | ||
|
||
for chickens in combinations(chicken_house, M): | ||
total = 0 | ||
for r in range(N): | ||
for c in range(N): | ||
if house[r][c] == 1: | ||
tmp = 9999 | ||
for chicken in chickens: | ||
tmp = min(tmp, abs(r - chicken[0]) + abs(c - chicken[1])) | ||
total += tmp | ||
|
||
result = min(result, total) | ||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters