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

34-H0ngJu #256

Merged
merged 3 commits into from
Nov 22, 2024
Merged

34-H0ngJu #256

merged 3 commits into from
Nov 22, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented Nov 16, 2024

πŸ”— 문제 링크

개λ˜₯벌레

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

1μ‹œκ°„??

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

image

이 λ¬Έμ œλŠ” ν‚₯은
(2 ≀ N ≀ 200,000, 2 ≀ H ≀ 500,000)

이 μ‘°κ±΄μž…λ‹ˆλ‹€.

사싀 문제 μžμ²΄λŠ” μ™„νƒμœΌλ‘œλ„ ν’€ μˆ˜λŠ” μžˆμ§€λ§Œ,
200,000 * 500,000 으둜 풀어버리면 μ‹œκ°„μ΄ˆκ³Όκ°€ λ°œμƒν•©λ‹ˆλ‹€.

κ·Έλž˜μ„œ μ‹œκ°„μ„ 쀄이기 μœ„ν•œ μ ‘κ·ΌμœΌλ‘œ
κ°€μž₯ λ¨Όμ € 이뢄탐색을 μƒκ°ν–ˆμŠ΅λ‹ˆλ‹€.

midλ₯Ό 작고 λ‘œμ§μ„ κ΅¬ν˜„ν•˜λŠ” κ³Όμ •μ—μ„œ μ—¬κΈ°μ„œ κ΅¬ν•΄μ§€λŠ” midκ°€ 뭐가 λ˜μ–΄μ•Ό ν•˜λŠ”μ§€ 잘 λͺ¨λ₯΄κ² λ”λΌκ³ μš”

이뢄탐색을 μ œμ™Έν•˜κ³  μ‹œκ°„μ„ 쀄일 수 μžˆλŠ” 방법은 λ­κ°€μžˆμ§€,,
ν•˜κ³  μ•Œκ³ λ¦¬μ¦˜ λΆ„λ₯˜λ₯Ό λ³΄λ‹ˆκΉŒ λˆ„μ ν•© 이 μžˆλ”λΌκ³ μš”


근데 why? λˆ„μ ν•©μœΌλ‘œ μ‹œκ°„μ„ 쀄일 수 μžˆλŠ”κ°€?

# info[odd] < fly and H - info[even] + 1 > fly 인 ꡬ간 쀑 μ΅œμ†Œλ₯Ό 찾으면 됨
# for fly in range(1,H+1):
#     broke = 0
#     for i in range(N):
#         if i%2 == 0: # 짝수인 경우
#             if H-info[i] + 1 > fly:
#                 continue
#             else:
#                 broke += 1
#         else:
#             if info[i] < fly:
#                 continue
#             else:
#                 broke += 1
#     if broke == min_broke:
#         broke_cnt += 1
#     elif broke < min_broke:
#         min_broke = broke
#         broke_cnt = 1

μ—¬κΈ°μ„œ λͺ¨λ“  μ„μˆœ,μ’…μœ μ„μ„ λ‹€ μ‚΄νŽ΄λ³΄κΈ° λ•Œλ¬Έμ—,
μœ„μ—μ„œ λ§ν•œλŒ€λ‘œ 200,000 * 500,000κ°€ λ˜μ–΄(이쀑 forλ¬Έ) μ‹œκ°„μ΄ˆκ³Όκ°€ λ°œμƒν•˜μ§€λ§Œ,

길이가 N개 이상인 μ„μˆœκ³Ό μ’…μœ μ„μ„ κ³„μ‚°ν•΄λ†“μœΌλ©΄,
2*100,000 + 500,000κ°€ λ˜μ–΄ μ‹œκ°„μ΄ˆκ³Όλ₯Ό 막을 수 μžˆμŠ΅λ‹ˆλ‹€.

μ‹œκ°„μ΄ˆκ³Ό -> 이쀑for문이 λŒ€λΆ€λΆ„ 문제..



κ·Έλž˜μ„œ λˆ„μ ν•©μœΌλ‘œ μ ‘κ·Όν•˜λ©΄,

μ„μˆœκ³Ό μ’…μœ μ„μ„ λ”°λ‘œ λΆ„λ¦¬ν•΄μ„œ
길이가 n 이상인 κ²ƒλ“€μ˜ 합을 μ €μž₯ν•΄μ€λ‹ˆλ‹€.

for i in range(H-1, 0, -1):
    down[i] += down[i+1]
    up[i] += up[i+1]

개λ˜₯λ²Œλ ˆκ°€ h-1 ~ h μ‚¬μ΄μ˜ ꡬ간을 λ‚  λ•Œ,
νŒŒκ΄΄ν•΄μ•Όν•˜λŠ” μ„μˆœκ³Ό μ’…μœ μ„μ€
μ„μˆœ[h] (길이가 h이상), μ’…μœ μ„[동꡴길이-h]μ΄λ―€λ‘œ

for i in range(1, H+1):
    broke = up[i] + down[H-i+1]
    if broke < min_broke:
        min_broke = broke
        broke_cnt = 1
    elif broke == min_broke:
        broke_cnt += 1

μš”λ‘œμ½”λ‘¬ μ΅œμ†Ÿκ°’μ„ κ°±μ‹ ν•΄μ£Όλ©΄ λ©λ‹ˆλ‹€.



λˆ„μ ν•©μœΌλ‘œ 문제λ₯Ό ν’€κ³ , λ‹€μ‹œ μ΄λΆ„νƒμƒ‰μœΌλ‘œ κ΅¬κΈ€λ§ν•΄μ„œ λ³΄λ‹ˆκΉŒ
μƒν•œμ„ , ν•˜ν•œμ„  κ°œλ…μœΌλ‘œ midλ₯Ό κ΅¬ν•΄μ„œ λ‘˜μ„ λ”ν•˜λŠ” μ‹μœΌλ‘œ κ΅¬ν˜„ν•  수 μžˆλ„€μš©

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

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.

이 λ¬Έμ œλŠ” ν‚₯은

(2 ≀ N ≀ 200,000, 2 ≀ H ≀ 500,000)

이 μ‘°κ±΄μž…λ‹ˆλ‹€.

γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹

저도 λˆ„μ ν•© λ°”λ‘œ λ– μ˜€λ₯΄κ³  ν’€μ—ˆλŠ”λ°,,

from collections import defaultdict
import sys

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

N, H = map(int, input().split())

floors = []
bottoms = []
for idx in range(N):
    height = int(input())
    height *= -1
        
    if idx%2==0: floors.append(height)
        
    else: bottoms.append(height)

floors.sort()
bottoms.sort()

f_prefix_sum = defaultdict(int)
p_f_h = 0
for f_h in floors:
    if p_f_h == 0 or p_f_h == f_h:
        f_prefix_sum[f_h] += 1
    else:
        f_prefix_sum[f_h] = f_prefix_sum[p_f_h] + 1
        
    p_f_h = f_h

b_prefix_sum = defaultdict(int)
p_b_h = 0
for b_h in bottoms:
    if p_b_h == 0 or p_b_h == b_h:
        b_prefix_sum[b_h] += 1
    else:
        b_prefix_sum[b_h] = b_prefix_sum[p_b_h] + 1
    
    p_b_h = b_h

b_temp = []
for b_h in range(H, 0, -1):
    if -1*b_h in b_prefix_sum: b_temp.append(b_prefix_sum[-1*b_h])
    else: 
        if b_temp: b_temp.append(b_temp[-1])
        else: b_temp.append(0)
b_temp.reverse()        

f_temp = []
for f_h in range(H, 0, -1):
    if -1*f_h in f_prefix_sum: f_temp.append(f_prefix_sum[-1*f_h])
    else: 
        if f_temp: f_temp.append(f_temp[-1])
        else: f_temp.append(0)

answer = 0
min_count = int(1e9)
for idx, (b, f) in enumerate(zip(b_temp, f_temp)):
    temp = b+f
    if min_count > temp:
        answer = 1
        min_count = temp
    elif min_count == temp:
        answer += 1

print(f"{min_count} {answer}")

제 μ½”λ“œλ³΄λ‹€ 홍μ₯¬λ₯΄ μ½”λ“œκ°€ 더 κ°„κ²°ν•˜κ³  μ΄μ˜λ„€μš” ,,, γ… γ… γ… γ… 

@H0ngJu H0ngJu merged commit 4f2c6c0 into main Nov 22, 2024
@H0ngJu H0ngJu deleted the 34-H0ngJu branch November 22, 2024 05:16
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.

2 participants