-
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.
Merge pull request #253 from AlgoLeadMe/33-H0ngJu
33-H0ngJu
- Loading branch information
Showing
2 changed files
with
146 additions
and
33 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 |
---|---|---|
@@ -1,36 +1,37 @@ | ||
## โ๏ธ ๊ธฐ๋ก | ||
|
||
| ์ฐจ์ | ๋ ์ง | ๋ฌธ์ ์ ํ | ๋งํฌ | ํ์ด | | ||
| :----: | :--------: | :-------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | | ||
| 1์ฐจ์ | 2024.03.05 | ํ | [ํ๋ก์ธ์ค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | | ||
| 2์ฐจ์ | 2024.03.07 | ํ | [๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 | | ||
| 3์ฐจ์ | 2024.03.10 | ํ | [N๋ฒ์งธ ํฐ ์](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | | ||
| 4์ฐจ์ | 2024.03.13 | ํ | [๋ฌธ์ ์ง](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | | ||
| 5์ฐจ์ | 2024.03.16 | ๊ตฌํ | [์์ธํธ์ค ๋ฌธ์ ](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | | ||
| 6์ฐจ์ | 2024.03.19 | ์คํ | [์คํฐ์](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | | ||
| 7์ฐจ์ | 2024.03.22 | DP | [1,2,3 ๋ํ๊ธฐ](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | | ||
| 8์ฐจ์ | 2024.03.16 | DP | [์ฌ์ด ๊ณ๋จ ์](https://www.acmicpc.net/problem/10844) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/170 | | ||
| 9์ฐจ์ | 2024.03.22 | DP | [RGB๊ฑฐ๋ฆฌ 2](https://www.acmicpc.net/problem/17404) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/172 | | ||
| 10์ฐจ์ | 2024.04.03 | BFS | [์จ๋ฐ๊ผญ์ง 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 | | ||
| 11์ฐจ์ | 2024.04.07 | ๊ตฌํ | [์ฌํ ๊ฒ์](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/178 | | ||
| 12์ฐจ์ | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 | | ||
| 13์ฐจ์ | 2024.05.06 | ์์ ํ์ | [๋ฆฌ๋ชจ์ปจ](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 | | ||
| 14์ฐจ์ | 2024.05.09 | DFS | [์นํจ๋ฐฐ๋ฌ](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 | | ||
| 15์ฐจ์ | 2024.05.14 | ๊ทธ๋ฆฌ๋ | [A์ B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 | | ||
| 16์ฐจ์ | 2024.05.14 | BFS | [๋ฑ๊ณผ ์ฌ๋ค๋ฆฌ ๊ฒ์](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 | | ||
| 17์ฐจ์ | 2024.05.22 | BFS | [์ ๋ก์์ฝ](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 | | ||
| 18์ฐจ์ | 2024.05.26 | DFS | [๊ณ๋์ผ๋ก ๊ณ๋์น๊ธฐ](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 | | ||
| 19์ฐจ์ | 2024.05.31 | DP | [ํฉ๋ถํด](https://www.acmicpc.net/problem/2225) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/202 | | ||
| 20์ฐจ์ | 2024.06.03 | ๋ฐฑํธ๋ํน | [์คํํธ์ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 | | ||
| 21์ฐจ์ | 2024.06.07 | ๊ทธ๋ฆฌ๋ | [ํ๋ณต ์ ์น์](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | | ||
| 22์ฐจ์ | 2024.08.06 | ํด์ | [์์](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 | | ||
| 23์ฐจ์ | 2024.08.10 | ํด์ | [๋ฒ ์คํธ์จ๋ฒ](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | | ||
| 24์ฐจ์ | 2024.08.17 | BFS | [์๊ธฐ์์ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | | ||
| 25์ฐจ์ | 2024.08.17 | DFS | [์น๊ตฌ๋น](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | | ||
| 26์ฐจ์ | 2024.08.24 | ๊ทธ๋ฆฌ๋ | [์ ์ ์ฌ์](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 | | ||
| 27์ฐจ์ | 2024.08.27 | DFS | [ํธ๋ฆฌ์ ์ง๋ฆ](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 | | ||
| 28์ฐจ์ | 2024.09.04 | ๋ฒจ๋งํฌ๋ | [ํ์๋จธ์ ](https://www.acmicpc.net/problem/11657) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/244 | | ||
| 29์ฐจ์ | 2024.09.06 | ๊ตฌํ | [ํฑ๋๋ฐํด](https://www.acmicpc.net/problem/14891) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/245 | | ||
| 30์ฐจ์ | 2024.09.27 | ์ํ | [Fly me to the Alpha Centauri](https://www.acmicpc.net/problem/1011) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/248 | | ||
| 31์ฐจ์ | 2024.10.05 | ์ ๋ ฌ | [์ ๊ธ๊ธฐ](https://www.acmicpc.net/problem/2170) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/249 | | ||
| ์ฐจ์ | ๋ ์ง | ๋ฌธ์ ์ ํ | ๋งํฌ | ํ์ด | | ||
| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | | ||
| 1์ฐจ์ | 2024.03.05 | ํ | [ํ๋ก์ธ์ค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | | ||
| 2์ฐจ์ | 2024.03.07 | ํ | [๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 | | ||
| 3์ฐจ์ | 2024.03.10 | ํ | [N๋ฒ์งธ ํฐ ์](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | | ||
| 4์ฐจ์ | 2024.03.13 | ํ | [๋ฌธ์ ์ง](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | | ||
| 5์ฐจ์ | 2024.03.16 | ๊ตฌํ | [์์ธํธ์ค ๋ฌธ์ ](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | | ||
| 6์ฐจ์ | 2024.03.19 | ์คํ | [์คํฐ์](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | | ||
| 7์ฐจ์ | 2024.03.22 | DP | [1,2,3 ๋ํ๊ธฐ](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | | ||
| 8์ฐจ์ | 2024.03.16 | DP | [์ฌ์ด ๊ณ๋จ ์](https://www.acmicpc.net/problem/10844) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/170 | | ||
| 9์ฐจ์ | 2024.03.22 | DP | [RGB๊ฑฐ๋ฆฌ 2](https://www.acmicpc.net/problem/17404) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/172 | | ||
| 10์ฐจ์ | 2024.04.03 | BFS | [์จ๋ฐ๊ผญ์ง 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 | | ||
| 11์ฐจ์ | 2024.04.07 | ๊ตฌํ | [์ฌํ ๊ฒ์](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/178 | | ||
| 12์ฐจ์ | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 | | ||
| 13์ฐจ์ | 2024.05.06 | ์์ ํ์ | [๋ฆฌ๋ชจ์ปจ](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 | | ||
| 14์ฐจ์ | 2024.05.09 | DFS | [์นํจ๋ฐฐ๋ฌ](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 | | ||
| 15์ฐจ์ | 2024.05.14 | ๊ทธ๋ฆฌ๋ | [A์ B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 | | ||
| 16์ฐจ์ | 2024.05.14 | BFS | [๋ฑ๊ณผ ์ฌ๋ค๋ฆฌ ๊ฒ์](https://www.acmicpc.net/problem/16928) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/191 | | ||
| 17์ฐจ์ | 2024.05.22 | BFS | [์ ๋ก์์ฝ](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 | | ||
| 18์ฐจ์ | 2024.05.26 | DFS | [๊ณ๋์ผ๋ก ๊ณ๋์น๊ธฐ](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 | | ||
| 19์ฐจ์ | 2024.05.31 | DP | [ํฉ๋ถํด](https://www.acmicpc.net/problem/2225) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/202 | | ||
| 20์ฐจ์ | 2024.06.03 | ๋ฐฑํธ๋ํน | [์คํํธ์ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 | | ||
| 21์ฐจ์ | 2024.06.07 | ๊ทธ๋ฆฌ๋ | [ํ๋ณต ์ ์น์](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | | ||
| 22์ฐจ์ | 2024.08.06 | ํด์ | [์์](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 | | ||
| 23์ฐจ์ | 2024.08.10 | ํด์ | [๋ฒ ์คํธ์จ๋ฒ](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | | ||
| 24์ฐจ์ | 2024.08.17 | BFS | [์๊ธฐ์์ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | | ||
| 25์ฐจ์ | 2024.08.17 | DFS | [์น๊ตฌ๋น](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | | ||
| 26์ฐจ์ | 2024.08.24 | ๊ทธ๋ฆฌ๋ | [์ ์ ์ฌ์](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 | | ||
| 27์ฐจ์ | 2024.08.27 | DFS | [ํธ๋ฆฌ์ ์ง๋ฆ](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 | | ||
| 28์ฐจ์ | 2024.09.04 | ๋ฒจ๋งํฌ๋ | [ํ์๋จธ์ ](https://www.acmicpc.net/problem/11657) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/244 | | ||
| 29์ฐจ์ | 2024.09.06 | ๊ตฌํ | [ํฑ๋๋ฐํด](https://www.acmicpc.net/problem/14891) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/245 | | ||
| 30์ฐจ์ | 2024.09.27 | ์ํ | [Fly me to the Alpha Centauri](https://www.acmicpc.net/problem/1011) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/248 | | ||
| 31์ฐจ์ | 2024.10.05 | ์ ๋ ฌ | [์ ๊ธ๊ธฐ](https://www.acmicpc.net/problem/2170) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/249 | | ||
| 32์ฐจ์ | 2024.10.14 | ์ด๋ถ ํ์ | [๊ธฐํ ๋ ์จ](https://www.acmicpc.net/problem/2343) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/252 | | ||
| 33์ฐจ์ | 2024.11.08 | ๋ฐฑํธ๋ํน | [๋ณ์ ๊ฑฐ๋ฆฌ ์ต์ํ](https://www.codetree.ai/training-field/frequent-problems/problems/min-of-hospital-distance/submissions?page=11&pageSize=5) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/253 | |
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,112 @@ | ||
import sys | ||
|
||
def input() : return sys.stdin.readline().rstrip() | ||
|
||
n, m = map(int, input().split()) | ||
hospital = [] | ||
person = [] | ||
info = [[] for _ in range(n)] | ||
|
||
# ์ฌ๋, ๋ณ์ ์ ๋ณด ๋ฐ๊ธฐ | ||
for i in range(n): | ||
info[i].extend(list(map(int, input().split()))) | ||
for j in range(n): | ||
if info[i][j] == 2: | ||
hospital.append((i,j)) | ||
if info[i][j] == 1: | ||
person.append((i,j)) | ||
|
||
distance = [[0 for _ in range(len(hospital))] for _ in range(len(person))] | ||
|
||
for i in range(len(person)): | ||
px, py = person[i] | ||
for j in range(len(hospital)): | ||
hx, hy = hospital[j] | ||
distance[i][j] = abs(px-hx) + abs(py-hy) | ||
|
||
# hospital ์์น ์ค์ m๊ฐ๋ฅผ ์ ํํด์ ์ต์๊ฐ ๊ตฌํ๊ธฐ | ||
hospital_arr = [i for i in range(len(hospital))] | ||
all_combinations = [] | ||
|
||
def combination(start, depth, combination_arr): | ||
if depth == m: # m๋งํผ ์ฐพ์ผ๋ฉด return | ||
all_combinations.append(combination_arr[:]) | ||
return | ||
for i in range(start, len(hospital_arr)): | ||
combination_arr.append(hospital_arr[i]) # ์์ ์ผ๋จ ๋ฃ๊ณ | ||
combination(i + 1, depth + 1, combination_arr) # ์ฌ๊ท ๋๋ฆผ | ||
combination_arr.pop() # ๋ค์ ๋ฝ์๊ฑฐ ๋ณต๊ท -> [1,2,3]์ ๊ตฌํ๋ฉด, 3๋นผ๊ณ ๋ค์ ๋ค์ ๋ฐ๋ณต๋ฌธ ๋ฃ์ด์ [1,2,4] ๊ฐ๋ฅ | ||
|
||
combination(0, 0, []) | ||
|
||
min_distance_sum = 1e9 | ||
for hospitals_combination in all_combinations: | ||
cur_distance = 0 | ||
|
||
for i in range(len(person)): | ||
dist = 1e9 | ||
for j in hospitals_combination: | ||
dist = min(dist, distance[i][j]) | ||
cur_distance += dist | ||
|
||
min_distance_sum = min(min_distance_sum, cur_distance) | ||
|
||
print(min_distance_sum) | ||
|
||
# --- combination ----- | ||
|
||
# import sys | ||
# import itertools | ||
|
||
# def input() : return sys.stdin.readline().rstrip() | ||
|
||
# n, m = map(int, input().split()) | ||
# hospital = [] | ||
# person = [] | ||
# info = [[] for _ in range(n)] | ||
|
||
# # ์ฌ๋, ๋ณ์ ์ ๋ณด ๋ฐ๊ธฐ | ||
# for i in range(n): | ||
# info[i].extend(list(map(int, input().split()))) | ||
# for j in range(n): | ||
# if info[i][j] == 2: | ||
# hospital.append((i,j)) | ||
# if info[i][j] == 1: | ||
# person.append((i,j)) | ||
|
||
# distance = [[0 for _ in range(len(hospital))] for _ in range(len(person))] | ||
|
||
# for i in range(len(person)): | ||
# px, py = person[i] | ||
# for j in range(len(hospital)): | ||
# hx, hy = hospital[j] | ||
# distance[i][j] = abs(px-hx) + abs(py-hy) | ||
|
||
# # hospital ์์น ์ค์ m๊ฐ๋ฅผ ์ ํํด์ ์ต์๊ฐ ๊ตฌํ๊ธฐ | ||
|
||
# min_distance_sum = 1e9 | ||
# combbination_arr = [i for i in range(len(hospital))] | ||
|
||
# for hospitals_combination in itertools.combinations(combbination_arr, m): | ||
# cur_distance = 0 | ||
|
||
# for i in range(len(person)): | ||
# dist = 1e9 | ||
# for j in hospitals_combination: | ||
# dist = min(dist, distance[i][j]) | ||
# cur_distance += dist | ||
|
||
# min_distance_sum = min(min_distance_sum, cur_distance) | ||
|
||
# print(min_distance_sum) | ||
|
||
# # ๋น์๋ฆฌ๋ฉด 0, ์ฌ๋์ด๋ฉด 1, ๋ณ์์ด๋ฉด 2 | ||
# # ์ถ๋ ฅ์ ์ต์ ๊ฑฐ๋ฆฌ | ||
|
||
# # ๋ณ์์ ์ ๋งํผ ๋ฐฐ์ด์ ์์ฑํด์, ๊ฐ ์ฌ๋๋ง๋ค์ ์ต์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ์ฐํ๋ค. | ||
# # ๊ฐ ๋ณ์์ ๊ฑฐ๋ฆฌ ์ด ํฉ์ ๊ณ์ฐํด์ ์ ๋ ฌํ๋ค. -> ๋ฌธ์ : ์ฌ๋๋ง๋ค ๋ค๋ฅธ ๋ณ์์ด ์ต์ ๊ฑฐ๋ฆฌ์ผ ์ ์์ง๋ง, ํด๋น ๊ฐ๋ฅ์ฑ์ ๋ฌด์ํ๊ฒ ๋จ | ||
|
||
# # ๊ฐ ์ฌ๋๋ง๋ค ๊ฐ ๋ณ์์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ์ฐํ๋ค. | ||
# # [[1,2,4,5], [1,2,4,5]]์ ํํ | ||
# # ๋ณ์ ์ค m๊ฐ๋ฅผ ๊ณ ๋ฅด๋ ์กฐํฉ | ||
# # ์กฐํฉ์์ ์ต์๊ฑฐ๋ฆฌ ๊ฐฑ์ ํ์ฌ ์ฐพ๊ธฐ |