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

86-tgyuuAn #265

Merged
merged 1 commit into from
Jan 28, 2025
Merged

86-tgyuuAn #265

merged 1 commit into from
Jan 28, 2025

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Jan 16, 2025

πŸ”— 문제 링크

ν†΅λ‚˜λ¬΄ 자λ₯΄κΈ°

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

1μ‹œκ°„

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

image

ν†΅λ‚˜λ¬΄μ˜ κΈΈμ΄λŠ” μ΅œλŒ€ 10얡이고, 자λ₯Ό 수 μžˆλŠ” νšŸμˆ˜λŠ” μ΅œλŒ€ 1만...!




μœ„ 문제λ₯Ό 보자마자 λ– μ˜¬λžλ˜ 생각은,

λ§Œμ•½ 자λ₯΄λŠ” νšŸμˆ˜κ°€ 1이라면 이 문제λ₯Ό λ§Œμ‘±ν•  졜적의 μž₯μ†ŒλŠ” 절반 이겠고,

자λ₯΄λŠ” νšŸμˆ˜κ°€ 2라면 μ •ν™•νžˆ 3λ“±λΆ„ ν•  수 μžˆλŠ” ν¬μΈνŠΈκ°€ μ •λ‹΅μ΄κ² κ΅¬λ‚˜..

4λ©΄ 5λ“±λΆ„, n이면 n+1 λ“±λΆ„ ν•  수 μžˆλŠ” 포인트겠ꡬ만...!




'어라, 그러면 이뢄 νƒμƒ‰μœΌλ‘œ 톡과할 수 μžˆλŠ” μ΅œμ†Œμ˜ μ΅œλŒ€ ν†΅λ‚˜λ¬΄ 길이λ₯Ό κ΅¬ν•΄μ„œ, κ·Έ 값을 λ§Œμ‘±ν•˜λŠ” 첫 번째 자λ₯΄λŠ” 포인트λ₯Ό κ΅¬ν•˜μž!'

라고 μƒκ°ν–ˆμŠ΅λ‹ˆλ‹€.

κ·Έλ ‡κ²Œ ν’€ 경우, 10μ–΅μ΄λΌλŠ” 큰 μˆ˜λ„ 이뢄 νƒμƒ‰μœΌλ‘œ νƒμƒ‰ν•˜λ©΄ O(30)이고,

자λ₯Ό 수 μžˆλŠ” ν¬μΈνŠΈκ°€ 1만 ꡰ데이기 λ•Œλ¬Έμ— μ™„μ „ 탐색을 ꡴렀도 30 * 1λ§Œμ΄λΌμ„œ 30만번으둜 ꡉμž₯히 λΉ λ₯΄κ²Œ ν’€ 수 μžˆμŠ΅λ‹ˆλ‹€...!




근데 이제 핡심은

// input
5 2 1
2 3

// output
3 2

κ°€ λ˜μ•Όν•˜λŠ”λ°,

길이가 2인 뢀뢄을 자λ₯΄λ‚˜ 3인 뢀뢄을 자λ₯΄λ‚˜ λͺ¨λ‘ λ§Œμ‘±ν•˜κΈ° λ•Œλ¬Έμ— 자λ₯Ό 수 μžˆλŠ” 첫 번째 포인트λ₯Ό 잘 선택해야 ν•©λ‹ˆλ‹€.

이λ₯Ό ꡬ할 λ•Œ μ²˜μŒλΆ€ν„° νƒμƒ‰ν•˜λ©΄μ„œ 자λ₯΄λŠ” 포인트λ₯Ό νƒμƒ‰ν•˜κ²Œ 되면 항상 3을 κ°€λ¦¬ν‚€κ²Œ λ˜λŠ”λ°,

이λ₯Ό λ°˜λŒ€λ‘œ λ’€μ§‘μ–΄μ„œ λ’€μ—μ„œλΆ€ν„° νƒμƒ‰ν•˜λ©΄ 쑰건을 λ§Œμ‘±ν•˜λ©΄μ„œ 자λ₯Ό 수 μžˆλŠ” κ°€μž₯ μ΅œμ†Œμ˜ 값을 탐색할 수 μžˆμŠ΅λ‹ˆλ‹€...!

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

@tgyuuAn tgyuuAn added tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. μž‘μ„± 쀑 ⏱️ labels Jan 16, 2025
@tgyuuAn tgyuuAn requested a review from H0ngJu January 16, 2025 08:43
@tgyuuAn tgyuuAn self-assigned this Jan 16, 2025
@tgyuuAn tgyuuAn marked this pull request as ready for review January 16, 2025 08:48
Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

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

생각보닀 문제 ν‘ΈλŠ”λ° μ‹œκ°„μ΄ μ˜€λž˜κ±Έλ ΈμŠ΅λ‹ˆλ‹€...! (μ΅œμ†Œ 쀑에 μ΅œλŒ€ << 이거 μ €λ²ˆ λ¬Έμ œλž‘ λΉ„μŠ·ν•˜λ„€μš”)
이뢄탐색일 것 κ°™μ•˜λŠ”λ° 잘라쀌과 λ™μ‹œμ— midλ₯Ό μ²˜λ¦¬ν•˜λŠ” λ‘œμ§μ—μ„œ μ˜€λ‹΅μ˜ λŠͺ에 λΉ μ‘Œλ„€μš” ,,,
μ§ˆκ²Œλž‘ λΉ„κ΅ν•΄λ³΄λ‹ˆ 자λ₯Ό 수 μžˆλŠ” νšŸμˆ˜κ°€ λ‚¨μ•„μžˆλ‹€λ©΄ μ•žμ˜ ν†΅λ‚˜λ¬΄μ—μ„œ 더 자λ₯Ό 수 μžˆλŠ” κ²½μš°κ°€ μžˆλ”λΌκ³ μš”.πŸ˜‘.

κ·Έλž˜μ„œ PRμ΄λž‘ λΈ”λ‘œκ·Έ ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.
μ €λŠ” whileλ¬Έ μ•ˆμ—μ„œ λ‹€ λ‘œμ§μ„ μ²˜λ¦¬ν• λ €κ³  ν–ˆλŠ”λ° ν•¨μˆ˜λ₯Ό 썼으면 μ’€ 더 κΉ”λ”ν•˜μ§€ μ•Šμ•˜λ‚˜ μ‹ΆμŠ΅λ‹ˆλ‹€.. ν•˜ν•˜

문제 ν‘ΈλŠλΌ κ³ μƒν•˜μ…¨κ³ , λ‹Ήκ·Ό ν™”μ΄νŒ… !!!!!! πŸ”₯πŸ₯•πŸ”₯πŸ₯•πŸ”₯πŸ₯•πŸ”₯πŸ₯•πŸ”₯πŸ₯•

33%μ—μ„œ λ²—μ–΄λ‚˜μ§€ λͺ»ν•œ μ½”λ“œ ..
import sys

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

L, K, C = map(int, input().split()) # 길이, μœ„μΉ˜, μ΅œλŒ€ 횟수
pos = list(map(int, input().split())) # 자λ₯Ό 수 μžˆλŠ” μœ„μΉ˜
pos.extend([0,L])
pos.sort()

# ν†΅λ‚˜λ¬΄μ˜ κ°€μž₯ κΈ΄ 쑰각을 μ΅œλŒ€ν•œ μž‘κ²Œ λ§Œλ“€κ³ , κ·Έ 길이λ₯Ό λ°˜ν™˜!
# λ§Œμ•½ 방법이 μ—¬λŸ¬κ°€μ§€λΌλ©΄, 처음 자λ₯΄λŠ” μœ„μΉ˜κ°€ μž‘μ€ 것을 좜λ ₯
# 좜λ ₯은 κ°€μž₯ κΈ΄ 쑰각의 길이와, κ·Έ μœ„μΉ˜λ₯Ό 좜λ ₯

start = 1
end = L
final_len = L
final_pos = 0

while start <= end:
    mid = (start + end) // 2
    flag = 1
    prev_pos = 0
    cnt = 0
    
    for i in range(1,len(pos)):
        if pos[i] - pos[prev_pos] > mid:
            cnt += 1
            if pos[i] - pos[i-1] > mid:
                flag = 0
                break
            prev_pos = i -1
        if cnt > C:
            flag = 0
            break
    
    if flag:
        final_len = mid
        cut = 0
        idx = len(pos) - 1
        
        for p in range(len(pos), -1, -1):
            if pos[idx] - pos[p] > mid:
                cut += 1
                idx = p + 1
                if cut > C:
                    break
        final_pos = pos[idx]
        end = mid - 1
    else:
        start = mid + 1
    

print(final_len, final_pos)

@tgyuuAn tgyuuAn merged commit f2a2a9d into main Jan 28, 2025
10 checks passed
@tgyuuAn tgyuuAn deleted the 86-tgyuuAn branch January 28, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. 리뷰 μ™„λ£Œ βœ”οΈ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants