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

67-tgyuuAn #223

Merged
merged 2 commits into from
Aug 6, 2024
Merged

67-tgyuuAn #223

merged 2 commits into from
Aug 6, 2024

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Jul 26, 2024

πŸ”— 문제 링크

μ„±λƒ₯κ°œλΉ„

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

2μ‹œκ°„

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

image

μ²˜μŒμ—” κ·Έλ¦¬λ””λ‘œ μ ‘κ·Όν–ˆλ‹€.

λ‹Ήμ—°νžˆ μ΅œλŒ€ 수λ₯Ό 좜λ ₯ν•  λ•Œμ—λŠ” μ„±λƒ₯κ°œλΉ„ μˆ˜κ°€ κ°€μž₯ μ κ²Œλ“œλŠ” 1둜 자릿수λ₯Ό λŠ˜λ¦¬λŠ”κ²Œ μ΄λ“μ΄λ‹ˆ,

ν™€μˆ˜κ°œμ˜ μ„±λƒ₯κ°œλΉ„μΌ λ•Œμ—λŠ” 3개둜 λ§Œλ“€ 수 μžˆλŠ” 7을 ν•˜λ‚˜ λ§Œλ“€κ³  남은 짝수개의 μ„±λƒ₯ κ°œλΉ„λŠ” λͺ¨λ‘ 1을 λΆ™μ—¬μ€€λ‹€.

큰 수λ₯Ό λ§Œλ“œλŠ” 것은 μ—„μ²­ 쉽닀.




근데... κ°€μž₯ μž‘μ€ μˆ˜λŠ” μ–΄λ–»κ²Œ λ§Œλ“€ 것인가 ...?

단지 자릿수만 쀄이면 λ˜λŠ” 것이 μ•„λ‹ˆλ‹€.

μ„±λƒ₯κ°œλΉ„ κ°―μˆ˜κ°€ 8이면, 19도 κ°€λŠ₯ν•˜κ³  91도 κ°€λŠ₯ν•˜λ©°,

10도 κ°€λŠ₯ν•˜κ³  16도 κ°€λŠ₯ν•˜κ³  61도 κ°€λŠ₯ν•˜λ‹€.

27, 72도 κ°€λŠ₯ν•˜κ³  λ“±λ“±...

자릿수λ₯Ό λ„˜μ–΄μ„œ 같은 자릿수 λ‚΄λΆ€μ—μ„œλ„ μž‘λ™ν•˜λŠ” λ‘œμ§μ„ λ§Œλ“€μ–΄μ•Ό ν•œλ‹€.

μ–΄λ–»κ²Œ μ–΄λ–»κ²Œ 주어진 λ³΄κΈ°μ—μ„œλ§Œ μž‘λ™ν•˜λŠ” μ•„λž˜ λ‘œμ§μ„ λ§Œλ“€μ–΄μ„œ μ œμΆœν•˜μ˜€κ³ ,

# 처음 μ ‘κ·Όν–ˆλ˜ 풀이 (μ˜€λ‹΅)

import sys

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

T = int(input())
for _ in range(T):
    count = int(input())
    min_count = count
    min = ""
    while min_count > 0:
        if min_count >= 8:
            if min == "":
                min_count -= 8
                min = "10" + min
            else:   
                min_count -= 6
                min = min + "0"
        
        elif min_count == 7:
            min_count -= 7
            min = min + "8"
            
        elif min_count == 6:
            min_count -= 6
            if min == "": min = "6"
            else: min = min + "0"

        elif min_count == 5:
            min_count -= 5
            min = min + "2"

        elif min_count == 4:
            min_count -= 4
            min = min + "4"

        elif min_count == 3:
            min_count -= 3
            min = min + "7"

        else:
            min_count -= 2
            min = min + "1"
    
    max_count = count
    max = ""
    while max_count > 0:
        if max_count %2 == 1:
            max_count -= 3
            max = max + "7"

        else:
            max_count -= 2
            max = max + "1"

    print(min, max)

κ·Έ κ²°κ³ΌλŠ” λ‹Ήμ—°νžˆ μ‹€νŒ¨μ˜€λ‹€.




λ„μ €νžˆ 이해가 κ°€μ§€μ•Šμ•„μ„œ κ²Œμ‹œλ¬Όμ„ λ’€μ Έ λ°˜λ‘€λ₯Ό μ°Ύμ•˜λ‹€.

input : 1 78

output : 108888888888 111111111111111111111111111111111111111

ν•˜μ§€λ§Œ λ‚΄ μ½”λ“œλŠ”

output : 10000000000004 111111111111111111111111111111111111111 을 λ±‰μœΌλ©° μ „μ‚¬ν•˜μ˜€λ‹€.




ν•œ 40λΆ„ μž‘κ³ μžˆλ‹€κ°€ λ„μ €νžˆ λͺ¨λ₯΄κ² μ–΄μ„œ μ•Œκ³ λ¦¬μ¦˜ λΆ„λ₯˜λ₯Ό ν™•μΈν•˜μ˜€λ‹€.




...!!

image

" λ‹€μ΄λ‚˜λ―Ή ν”„λ‘œκ·Έλž˜λ° "

μ΄μƒν•˜κ²Œ μ € ν‚€μ›Œλ“œλ₯Ό 보자마자 계단 수 κ°€ λ– μ˜¬λžκ³ ,

DPν…Œμ΄λΈ”μ˜ 인덱슀λ₯Ό μ‚¬μš©ν•œ μ„±λƒ₯κ°œλΉ„ 개수둜 작고,

οΏ½ν˜„μž¬ μΈλ±μŠ€μ—μ„œ n개λ₯Ό 더 μ‚¬μš©ν•˜μ—¬ λ§Œλ“€ 수 μžˆλŠ” μ΅œλŒ€ κ°’κ³Ό μ΅œμ†Œ 값을 κ°±μ‹ ν•˜λ©° λŒμ•„μ€€λ‹€.

말이 되게 μ–΄λ €μš΄λ°,

    count = int(input())

    # DP[i][j] μ—μ„œ iλŠ” μ‚¬μš©ν•œ μ„±λƒ₯κ°œλΉ„ 개수, j=0일 λ•Œμ—λŠ” μ΅œμ†Œ κ°’, j=1일 λ•Œμ—λŠ” μ΅œλŒ€ 값이 λ“€μ–΄κ°„λ‹€.
    DP = [[str(int(1e9)), "0"] for _ in range(count+1)]
    DP[0][0] = "0"

    for now_idx in count:

        # ν˜„μž¬ μ‚¬μš©ν•œ μ„±λƒ₯κ°œλΉ„ κ°œμˆ˜μ—μ„œ 2개λ₯Ό μΆ”κ°€μ μœΌλ‘œ μ‚¬μš©ν•  수 있으면,
        if now_idx + 2 <= count:
            # λ§Œμ•½ ν˜„μž¬ μ‚¬μš©ν•œ μ„±λƒ₯κ°œλΉ„ κ°œμˆ˜μ—μ„œ λ§Œλ“€ 수 μžˆλŠ” μˆ˜μ—μ„œ 뒀에 "1"을 뢙인 값이 더 μž‘μ„ 경우 0번째 항을 κ°±μ‹ ν•΄μ€€λ‹€.
            if int(DP[now_idx + 2][0]) > int(DP[now_idx + 2][0] + "1"):
                DP[now_idx + 2][0] = DP[now_idx + 2][0] + "1"

            # λ§Œμ•½ ν˜„μž¬ μ‚¬μš©ν•œ μ„±λƒ₯κ°œλΉ„ κ°œμˆ˜μ—μ„œ λ§Œλ“€ 수 μžˆλŠ” μˆ˜μ—μ„œ 뒀에 "1"을 뢙인 값이 더 클 경우 1번째 항을 κ°±μ‹ ν•΄μ€€λ‹€.
            if int(DP[now_idx + 2][1]) < int(DP[now_idx + 2][1] + "1"):
                DP[now_idx + 2][1] = DP[now_idx + 2][1] + "1"

와 같은 λ°©μ‹μœΌλ‘œ 말이닀.

지문과 λ¬Έμ œκ°€ κ°„λ‹¨ν•˜κ³  ν•¨μ •μœΌλ‘œ 빠지기 μ‰¬μš΄ 문제인 것 κ°™λ‹€.

DPλ₯Ό μ™œ λ– μ˜¬λ¦¬μ§€ λͺ»ν–ˆμ„κΉŒ...? 계단 μˆ˜μ™€ λΉ„μŠ·ν•œλ° 말이닀.

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

@tgyuuAn tgyuuAn added tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. μž‘μ„± 쀑 ⏱️ labels Jul 26, 2024
@tgyuuAn tgyuuAn self-assigned this Jul 26, 2024
@tgyuuAn tgyuuAn force-pushed the 67-tgyuuAn branch 2 times, most recently from f4117df to e2e2e01 Compare July 26, 2024 04:24
@tgyuuAn tgyuuAn marked this pull request as ready for review July 26, 2024 04:55
@tgyuuAn tgyuuAn merged commit 243234a into main Aug 6, 2024
@tgyuuAn tgyuuAn deleted the 67-tgyuuAn branch August 6, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
λ‚΄λ‹€ 버린 PR πŸ—‘οΈ tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant