Skip to content
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

13-H0ngJu #181

Merged
merged 93 commits into from
May 10, 2024
Merged

13-H0ngJu #181

merged 93 commits into from
May 10, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented May 6, 2024

πŸ”— 문제 링크

리λͺ¨μ»¨

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1μ‹œκ°„ +a

✨ μˆ˜λ„ μ½”λ“œ

처음 문제λ₯Ό 보고 κ΅¬ν˜„ or 완전탐색을 μƒκ°ν–ˆμŠ΅λ‹ˆλ‹€.
μ–΄λ–»κ²Œ μ ‘κ·Όν•΄μ•Όκ² λ‹€! λΌλŠ”κ²Œ λ– μ˜€λ₯΄μ§€ μ•Šλ”λΌκ³ μš”


μˆ˜λ„ μ½”λ“œλŠ” μ•„λž˜μ™€ κ°™μŠ΅λ‹ˆλ‹€.
  1. cnt에 λˆ„λ₯΄λŠ” 횟수λ₯Ό μ €μž₯ν•œλ‹€.
  2. for 문을 돌며 λˆ„λ₯Ό 수 μžˆλŠ” 수λ₯Ό ν™•μΈν•œλ‹€.
    1. κ³ μž₯λ‚œ λ²„νŠΌμ΄ 포함 λ˜μ–΄ 있으면 Falseλ₯Ό, 포함 λ˜μ–΄ μžˆμ§€ μ•ŠμœΌλ©΄ Trueλ₯Ό λ°˜ν™˜ν•œλ‹€.
  3. λ§Œμ•½ λˆ„λ₯Ό 수 μžˆλŠ” 경우, κΈ°μ‘΄ cnt에 λ‹΄κ²¨μžˆλŠ” κ°’κ³Ό λΉ„κ΅ν•˜μ—¬ μ΅œμ†Ÿκ°’μ„ cnt에 μ €μž₯ν•œλ‹€.

μ—¬κΈ°μ„œ μ•½κ°„ μ£Όμ˜ν•΄μ•Ό ν•  점이 μžˆμŠ΅λ‹ˆλ‹€.

μ €λŠ” N<=500,000μ΄λΌμ„œ for문을 반볡문 λ²”μœ„λ„ range(500001)둜 μž‘μ•˜μŠ΅λ‹ˆλ‹€. 그런데, N = 500000, M = 8, btn = [0 2 3 4 6 7 8 9]인 κ²½μš°μ— λŒ€ν•΄μ„œλŠ” μ˜¬λ°”λ₯Έ 닡이 λ‚˜μ˜€μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.




이 λΆ€λΆ„μ—μ„œ λ§‰ν˜€μ„œ 질문 κ²Œμ‹œνŒμ„ μ°Έκ³ ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

일단 for문을 500000κΉŒμ§€μ˜ λ²”μœ„μ—μ„œλ§Œ 돌릴 경우, νŠΉμ • 채널에 λŒ€ν•˜μ—¬ + λ₯Ό κ³ λ €ν•  뿐, -λ₯Ό κ³ λ €ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.



즉, μ•„λž˜ 채널뢀터 +ν•˜μ—¬ target channel둜 κ°€λŠ” 것이 μ•„λ‹ˆλΌ, μœ— μ±„λ„μ—μ„œ μ•„λž˜ μ±„λ„λ‘œ -ν•˜μ—¬ target channel둜 κ°€λŠ” 경우λ₯Ό μƒκ°ν•˜λ©΄

반볡문의 λ²”μœ„λŠ” 500,000 * 2인 1,000,000κ°€ λ©λ‹ˆλ‹€.


N = int(input())
M = int(input())
btn = list(map(int, input().rsplit()))

target = abs(N-100)
cnt = target

for i in range(1000001):
    check = True
    for str_i in str(i):
        if int(str_i) in btn:
            check = False
            break

    if check:
        cnt = min(cnt, abs(i - N)+len(str(i)))

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@tgyuuAn
Copy link
Member

tgyuuAn commented May 10, 2024

홍μ₯¬λ₯΄ μ½”λ“œ λΈ”λŸ­ ν•˜μ΄λΌμ΄νŒ… μ•ˆλ˜μ–΄μžˆμ–΄μ„œ μ œκ°€ ν•˜μ΄λΌμ΄νŒ… λ„£μ–΄λ†¨μ”λ‹ˆλ‹€!

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아놔......... μƒκ°ν•΄λ³΄λ‹ˆκΉŒ N이 50λ§Œλ°–μ— μ•ˆλ˜λ‹ˆκΉŒ 브루트 포슀둜 ν’€ 수 μžˆμ—ˆλ„€μš”....

import sys

def input(): return sys.stdin.readline().rstrip()

INF = int(1e9)
N = int(input())
M = int(input())
not_working_buttons = set(input().split())
working_buttons = set(str(x) for x in range(10))
working_buttons -= not_working_buttons
min_gap = max(100 - N, N - 100)
answer = min_gap

def dfs(num, depth, working_buttons):
    global answer, min_gap
    
    if len(str(N))-1 <= depth and depth <= len(str(N))+1:
        gap = max(int(num) - N, N - int(num))
        if min_gap >= gap:
            answer = min(answer,(depth + gap))
            min_gap = gap
            
    if depth == len(str(N))+1: return

    for button in working_buttons:
        dfs(num+button, depth+1, working_buttons)

min_gap = max(100 - N, N - 100)
for button in working_buttons:
    if button == "0":
        gap = N
        if min_gap > gap:
            answer = N+1
            min_gap = N
        continue
    
    dfs(button, 1, working_buttons)

print(answer)

image




λ°”λΉ μ„œ μ•Œκ³ λ¦¬μ¦˜ μ’€ μ‰¬μ—ˆλ”λ‹ˆ 감 λ‹€ μžƒμ—ˆλ‚˜λ΄„λ‹ˆλ‹€.................

λ°”λ‘œ DFSκ°€ λ– μ˜¬λžλŠ”λ° 브루트포슀둜 ν’€λ©΄ 더 μ‰¬μ› μ—ˆλ„€......................μš”...............................

μ˜€λ²„μ—”μ§€λ‹ˆμ–΄λ§ γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… γ… 

@H0ngJu H0ngJu merged commit 37bdeaf into main May 10, 2024
1 check passed
@H0ngJu H0ngJu deleted the 13-H0ngJu branch May 10, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants