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

8-wkdghdwns199 #36

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wkdghdwns199/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
| 5μ°¨μ‹œ | 2024.02.14 | μ•½μˆ˜, λ°°μˆ˜μ™€ μ†Œμˆ˜ | <a href="https://www.acmicpc.net/problem/17103">λ‹€μŒ μ†Œμˆ˜</a> | <a href="">2024.02.14</a> |
| 6μ°¨μ‹œ | 2024.02.16 | μ•½μˆ˜, λ°°μˆ˜μ™€ μ†Œμˆ˜ | <a href="https://www.acmicpc.net/problem/13909">μ°½λ¬Έ λ‹«κΈ°</a> | <a href="">2024.02.16</a> |

| 8μ°¨μ‹œ | 2024.02.16 | μŠ€νƒ, 큐, 덱 | <a href="https://www.acmicpc.net/problem/12789">도킀도킀 κ°„μ‹λ“œλ¦¬λ―Έ</a> | <a href="">2024.02.16</a> |

23 changes: 23 additions & 0 deletions wkdghdwns199/μŠ€ν…_큐_덱/ACM-12789.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
N = int(input())
order_list = list(map(int, input().split()))
order = 1
stack = []

# 5 4 2 3 1

while order_list :
if order_list[0] == order:
order_list.pop(0)
Copy link
Member

Choose a reason for hiding this comment

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

문제 μœ ν˜•λ•Œλ¬Έμ— μŠ€νƒ μ“°μ‹  것 같은데 λ”°λ‘œ 문제 μœ ν˜• μ•Œμ•„λ„ 큐둜 μ¨μ„œ μ‹œκ°„ λ‚­λΉ„λ₯Ό μ€„μ΄λŠ”κ²Œ μ’‹μ•„λ³΄μž…λ‹ˆλ‹€!!!

λ”°λ‘œ μŠ€νƒμ˜ pop(0)λ₯Ό 해버리면 O(n)이 κ±Έλ¦¬μ§€λ§Œ
큐의 popleft()λ₯Ό μ‚¬μš©ν•˜λ©΄ O(1)이 κ±Έλ €μ„œ n의 μ΅œλŒ€κ°’μ΄ 크면 μ‹œκ°„μ΄ˆκ³Όκ°€ 걸릴 것 κ°™μ•„μ„œ

order+=1
else :
stack.append(order_list.pop(0))

while stack :
if stack[-1] == order:
stack.pop()
order +=1
else :
break


print('Nice') if len(stack)==0 else print('Sad')