-
Notifications
You must be signed in to change notification settings - Fork 2
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
33-H0ngJu #253
Conversation
λ¬Έμ κ° λμ μ΅λ€ νλλ... λ°±μ€μ 15686 μΉν¨ λ°°λ¬ λ¬Έμ λ μλ²½νκ² λμΌνλ€μ γ
γ
|
μΆκ°λ‘ 리μ€νΈ μ¬λΌμ΄μ±μ λ§μνμ κ²μ²λΌ "μμ 볡μ¬"μ
λλ€. |
μ¬λΌμ΄μ±μ μμ 볡μ¬μμ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from itertools import combinations
import sys
def input(): return sys.stdin.readline().rstrip()
N, M = map(int, input().split())
hospital = []
people = []
for row in range(N):
_input = list(map(int, input().split()))
for col in range(N):
if _input[col] == 1:
people.append((row, col))
elif _input[col] == 2:
hospital.append((row, col))
answer = int(1e9)
for items in combinations(hospital, M):
dedicate = 0
for person in people:
_min = int(1e9)
for item in items:
temp = abs(item[0] - person[0]) + abs(item[1] - person[1])
_min = min(_min, temp)
dedicate += _min
answer = min(answer, dedicate)
print(answer)
itertools... κ°μ¬κΈ°κΈ΄νμ£ ....
λ°±μ€μ Nκ³Ό M μλ¦¬μ¦ λ¬Έμ μ§ itertools μμ°κ³ νλ©΄ ν¨κ³Όμ μ΄μμ!
λ¬Έμ μ λλ‘ μμ½κ³ 40λΆ λ λ¦Ό..
|
μ μ λ κ·Έλ κ² μκ³ μμ΅λλ€ ~. ~ |
π λ¬Έμ λ§ν¬
λ³μ 거리 μ΅μν
βοΈ μμλ μκ°
50M
β¨ μλ μ½λ
μ΄λ²μλ μΌμ± SW κΈ°μΆ λ¬Έμ μ€μ νλλ₯Ό μ ννμ΅λλ€!
μ΄ λ¬Έμ λ₯Ό μ΄λ»κ² νκΉ... νλ€κ° Nκ° μ€μ Mκ° λ½μμ κ·Έλ₯ μ΅μ 거리 κ°±μ νλ©΄ λκ² λ€ ν΄μ μλ νλ¦μΌλ‘ νμμ΅λλ€.
2μμ μ λ
itertools
μcombinations ν¨μ
λ₯Ό μ¬μ©νμ΄μκ·Όλ° λκ° λ¬Έμ μμ μꡬνλκ² μ΄κ² λ§λ? μΆμ΄μ λ€λ₯Έ νμ΄λ₯Ό μ°Ύμ보λ μ€μ
μΌμ± μ½ν μμλ itertools importνλ κ²μ λ§λλ€κ³ νλλΌκ³ μ?
κ·Έλμ combinations ν¨μλ₯Ό λ°λ‘ ꡬνν΄μ νλ² λ νμμ΅λλ€.
μ΄λ¬λλ°
μλ νμ΄μ...
π μλ‘κ² μκ²λ λ΄μ©
slicingμ κΉμ 볡μ¬μΌκΉμ μμ 볡μ¬μΌκΉμ?
μ λ slicingμ΄ deepcopyλΌκ³ μκ°νμ΅λλ€.
첫λ²μ§Έ μΌμ΄μ€ )
μ΄λ new_arrκ³Ό arrμ΄ λ©λͺ¨λ¦¬ μ£Όμκ° λ€λ₯΄λκΉμ
λλ²μ§Έ μΌμ΄μ€ )
slicingμ μμ 볡μ¬λ€λΌλ λΈλ‘κ·Έ κΈμ λ³΄κ² λμλλ°μ
κΈμ μμ μΈ
print(id(a[1]), '=', id(b[1]))
λ₯Ό 보면 κ²°κ΅ λ©λͺ¨λ¦¬ μ£Όμκ° κ°κ² λμμ slicingμ μμ 볡μ¬λΌκ³ λ§νλλΌκ³ μ2μ°¨μ λ°°μ΄μ slicingμΌλ‘ 볡μ¬λ₯Ό νλ κ²½μ°μ,
λ°κΉ₯ 리μ€νΈμλ§ μ£Όμκ° λ¬λΌμ§λ κ²μ μ μ μμ΅λλ€.
λ΄λΆ 리μ€νΈλ κ°μ κ³³μ μ°Έμ‘°νλ κ±°μ£ .
μ λ slicingμ μμ 볡μ¬λΌκ³ μκ°νκΈ°λ‘ νμ΅λλ€. (κ·Όλ° κΉμ 볡μ¬μΈμ² νλ...)
λ€λ₯Έ λΆλ€μ slicingμ΄ μμ 볡μ¬, κΉμ λ³΅μ¬ μ€ λ¬΄μμ΄λΌκ³ μκ°νμλμ?