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

21-avocado-13 #94

Merged
merged 3 commits into from
Mar 14, 2024
Merged

21-avocado-13 #94

merged 3 commits into from
Mar 14, 2024

Conversation

avocado-13
Copy link
Member

@avocado-13 avocado-13 commented Mar 9, 2024

πŸ”— 문제 링크

λ°±μ€€ | Cow line

문제 μ„€λͺ…

농뢀 John의 N마리의 μ†Œκ°€ 쀄을 λ§Œλ“€κ³  μžˆλŠ” 쀑이닀. μ²˜μŒμ—λŠ” 쀄에 아무 μ†Œκ°€ μ—†μ§€λ§Œ μ΄λ”°κΈˆ ν•œ λ§ˆλ¦¬μ”© μ€„μ˜ μ™Όμͺ½ ν˜Ήμ€ 였λ₯Έμͺ½μœΌλ‘œ λ“€μ–΄μ˜¨λ‹€. λ•Œλ•Œλ‘œ, 였λ₯Έμͺ½ ν˜Ήμ€ μ™Όμͺ½μ— μžˆλŠ” λͺ‡λ§ˆλ¦¬μ˜ μ†Œλ“€μ€ 그듀이 μ’‹μ•„ν•˜λŠ” λͺ©μž₯에 풀을 뜯으러 λ‚˜κ°„λ‹€. JλŠ” 이 μ†Œλ“€μ„ λ”°λΌλ‹€λ‹ˆλŠ” 데 어렀움을 κ²ͺκ³  μžˆλ‹€. κ·Έλ₯Ό λ„μ™€μ£Όμž.

μ†Œλ“€μ€ μ²«λ²ˆμ§ΈλΆ€ν„° N번째 μ†ŒκΉŒμ§€ 쀄에 λ“€μ–΄μ˜€λŠ”λ°, ν•œ 번 쀄을 λ– λ‚œ μ†ŒλŠ” μ ˆλŒ€ λ‹€μ‹œ λ“€μ–΄μ˜€μ§€ μ•ŠλŠ”λ‹€. ν”„λ‘œκ·Έλž¨μ—λŠ” S(1 <= S <= 100,000)의 μž…λ ₯ 사양이 주어지며, 각각은 ν•œ 쀄에 λ‚˜νƒ€λ‚˜κ³  두 가지 μœ ν˜• 쀑 ν•˜λ‚˜μ΄λ‹€:

  • μ†Œ ν•œ λ§ˆλ¦¬κ°€ 쀄에 λ“€μ–΄μ˜¨λ‹€. (λ§€κ°œλ³€μˆ˜λŠ” μ™Όμͺ½ λ˜λŠ” 였λ₯Έμͺ½μ— μžˆλŠ”μ§€ μ—¬λΆ€λ₯Ό λ‚˜νƒ€λ‚Έλ‹€).
  • K마리의 μ†Œκ°€ μ™Όμͺ½ λ˜λŠ” 였λ₯Έμͺ½μ—μ„œ 쀄을 λΉ μ Έλ‚˜κ°„λ‹€. (제곡된 λ§€κ°œλ³€μˆ˜λ‘œ μ†Œμ˜ μˆ˜μ™€ μ–΄λŠ μͺ½μΈμ§€ λͺ¨λ‘ μ •μ˜).

μž…λ ₯ 라인은 μˆ˜ν–‰ν•  수 μ—†λŠ” μž‘μ—…μ„ μš”μ²­ν•˜μ§€ μ•ŠλŠ”λ‹€.

λͺ¨λ“  μž…λ ₯ 라인이 처리된 ν›„ ν”„λ‘œκ·Έλž¨μ€ 라인에 μžˆλŠ” μ†Œλ₯Ό μ™Όμͺ½μ—μ„œ 였λ₯Έμͺ½ μˆœμ„œλŒ€λ‘œ 좜λ ₯ν•΄μ•Ό ν•œλ‹€. λ§ˆμ§€λ§‰ 쀄은 μž…λ ₯ 사양이 끝날 λ•Œ λΉ„μ–΄ μžˆμ§€ μ•Šμ•„μ•Ό ν•œλ‹€.

μž…λ ₯

  • 첫번째 쀄: μ •μˆ˜ S
  • λ‘λ²ˆμ§Έ 쀄 ~ S + 1 λ²ˆμ§Έμ€„ : μž…λ ₯ 사양은 μ•„λž˜ 4가지 양식 쀑 ν•˜λ‚˜λ‹€.
    • A L - ν•œ 마리의 μ†Œκ°€ μ€„μ˜ μ™Όμͺ½μ— λ“€μ–΄μ˜¨λ‹€.
    • A R - ν•œ 마리의 μ†Œκ°€ μ€„μ˜ 였λ₯Έμͺ½μ— λ“€μ–΄μ˜¨λ‹€.
    • D L K - K마리의 μ†Œκ°€ μ€„μ˜ μ™Όμͺ½μ—μ„œ λ– λ‚œλ‹€.
    • D R K - K마리의 μ†Œκ°€ μ€„μ˜ 였λ₯Έμͺ½μ—μ„œ λ– λ‚œλ‹€.

좜λ ₯

쀄에 μžˆλŠ” μ†Œμ˜ 번호λ₯Ό μ™Όμͺ½μ—μ„œ 였λ₯Έμͺ½ μˆœμ„œλ‘œ, ν•œ 쀄에 ν•˜λ‚˜μ”© 좜λ ₯해라.

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

30λΆ„

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

제λͺ©μ„-μž…λ ₯ν•΄μ£Όμ„Έμš”_-001

N Jκ°€ λ³΄μœ ν•œ μ†Œμ˜ 마리 수 == μž…λ ₯받을 μ‚¬μ–‘μ˜ 개수
queue 쀄을 ν‘œν˜„ν•  자료ꡬ쑰
cowNum μ†Œμ—κ²Œ λΆ€μ—¬ν•  번호(1λΆ€ν„° μ‹œμž‘)
cmd 각 쀄에 μž…λ ₯ λ°›λŠ” 사양
action A ν˜Ήμ€ D에 ν•΄λ‹Ή
side L ν˜Ήμ€ R에 ν•΄λ‹Ή

Caution

각 μ†Œμ˜ 번호λ₯Ό λΆ€μ—¬ν•  λ•Œ, μ†Œμ˜ 번호인 cowNum은 λ“€μ–΄κ°€λŠ” μ†Œμ— ν•œν•΄μ„œ 1λ²ˆμ§ΈλΆ€ν„° μ‹œμž‘λ˜κ³ , +1μ”© λœλ‹€λŠ” 것을 μœ μ˜ν•΄μ•Ό ν•œλ‹€.


  • μ†Œλ“€μ΄ λ“€μ–΄κ°ˆ 쀄을 생성해쀀닀
queue = deque()
  • N번 만큼 λ°˜λ³΅λ¬Έμ„ λŒλ©΄μ„œ μž…λ ₯ 사양에 맞게 μˆ˜ν–‰ν•œλ‹€.
for _ in range(N):
    cmd = input().split() # 곡백으둜 κ΅¬λΆ„ν•΄μ„œ μž…λ ₯λ°›μŒ 
    action, side = cmd[0], cmd[1] 
    if action == "A":
        if side == "L":
            queue.appendleft(cowNum) # μ€„μ˜ μ™Όμͺ½μ— cowNumμ΄λΌλŠ” 번호λ₯Ό κ°€μ§€λŠ” μ†Œλ₯Ό λ„£μ–΄μ€Œ
        else:
            queue.append(cowNum)# μ€„μ˜ 였λ₯Έμͺ½μ— cowNumμ΄λΌλŠ” 번호λ₯Ό κ°€μ§€λŠ” μ†Œλ₯Ό λ„£μ–΄μ€Œ
        cowNum += 1 # λ‹€μŒ λ“€μ–΄μ˜¬ 수λ₯Ό μœ„ν•΄μ„œ +1 ν•΄μ€€λ‹€. 
    else : # action == "D"
        K = cmd[2]
        if side == "L":
            for _ in range(int(K)):
                queue.popleft() # K마리의 μ†Œλ₯Ό μ™Όμͺ½μ—μ„œ λΉΌμ€€λ‹€. 
               
        else:
            for _ in range(int(K)):# K마리의 μ†Œλ₯Ό 였λ₯Έμͺ½μ—μ„œ λΉΌμ€€λ‹€. 
                queue.pop()
  • ν•œ 쀄에 ν•˜λ‚˜μ”© 쀄에 μžˆλŠ” μ†Œμ˜ 번호λ₯Ό 좜λ ₯ν•œλ‹€.
print(*queue,sep="\n") #리슀트의 μš”μ†Œλ₯Ό μ–ΈνŒ¨ν‚Ήν•΄μ„œ 좜λ ₯, κ°œν–‰λ¬Έμžλ‘œ κ΅¬λΆ„ν•΄μ„œ 

μ΅œμ’…μ½”λ“œ

import sys
from collections import deque

input = sys.stdin.readline
queue = deque()
cowNum = 1 
N = int(input()) # 쀄에 μ„€ μ†Œκ°€ λͺ‡λ§ˆλ¦¬μΈμ§€ μž…λ ₯λ°›κΈ°
for _ in range(N):
    cmd = input().split()
    action, side = cmd[0], cmd[1]
    if action == "A":
        if side == "L":
            queue.appendleft(cowNum)
        else:
            queue.append(cowNum)
        cowNum += 1 
    else : # action == "D"
        K = cmd[2]
        if side == "L":
            for _ in range(int(K)):
                queue.popleft()
               
        else:
            for _ in range(int(K)):
                queue.pop()

print(*queue,sep="\n")

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

PR μ—…λ‘œλ“œκ°€ λŠ¦μ€ 점 정말 μ£„μ†‘ν•©λ‹ˆλ‹€.

Copy link
Collaborator

@Hwangyerin Hwangyerin left a comment

Choose a reason for hiding this comment

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

action, side 직관적인 λ³€μˆ˜λͺ… 쒋은 것 κ°™μŠ΅λ‹ˆλ‹€:)
21μ°¨μ‹œ μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€ μ‹œν˜„λ‹˜!

Comment on lines +19 to +25
if side == "L":
for _ in range(int(K)):
queue.popleft()

else:
for _ in range(int(K)):
queue.pop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

for문이 μ€‘λ³΅λ˜λŠ” μ½”λ“œμΈ 것 κ°™μ•„μš”! 쑰건문 μ•ˆμ— for문을 λ„£λŠ” 방식도 μ’‹μ§€λ§Œ forλ¬Έ μ•ˆμ— 쑰건문을 λ„£λŠ” 건 μ–΄λ–¨κΉŒμš”?

for _ in range(int(K)):
    if side == "L":
        queue.popleft()
    else:
        queue.pop()

Copy link
Member Author

Choose a reason for hiding this comment

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

였였 λ§žλ„€μš”!! 훨씬 κΉ”λ”ν•΄μ‘Œλ„€μš” κ°μ‚¬ν•©λ‹ˆλ‹· πŸ’ž

Copy link
Collaborator

@LJEDD2 LJEDD2 left a comment

Choose a reason for hiding this comment

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

직관적인 λ³€μˆ˜λͺ… 덕뢄에 μ½”λ“œλ₯Ό μ‰½κ²Œ 이해할 수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€ !
이번 μ°¨μ‹œ PR도 κ³ μƒν•˜μ…¨μŠ΅λ‹ˆλ‹€ ☘️

for _ in range(int(K)):
queue.pop()

print(*queue,sep="\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

였 γ…Žγ…Žγ…Ž 좜λ ₯λ¬Έ κΉ”λ”ν•˜κ²Œ μž‘μ„±ν•΄μ£Όμ‹  λΆ€λΆ„ μ’‹λ„€μš” :)

Copy link
Member Author

Choose a reason for hiding this comment

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

μ •μ€λ‹˜ 덕뢄에 μ•Œκ²Œλœ sep μž…λ‹ˆλ‹€ πŸ˜‰(ΰΈ‡ β€’_β€’)ΰΈ‡

Copy link
Member

@janghw0126 janghw0126 left a comment

Choose a reason for hiding this comment

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

λ³€μˆ˜λͺ…을 κΉ”λ”ν•˜κ²Œ μ μ–΄μ£Όμ…”μ„œ μ½”λ“œλ₯Ό 더 μ‰½κ²Œ νŒŒμ•…ν•  수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€!
또 μˆ˜λ„ μ½”λ“œμ— μžˆλŠ” 첨뢀 이미지 덕뢄에 문제λ₯Ό 더 μ •ν™•ν•˜κ²Œ μ΄ν•΄ν•˜κ³  μ½”λ“œλ₯Ό 지 수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€πŸ€

이번 PR도 정말 정말 μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€!😘😘

@avocado-13 avocado-13 merged commit 4d7eebc into main Mar 14, 2024
@avocado-13 avocado-13 deleted the 21-avocado-13 branch March 14, 2024 13:45
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