-
Notifications
You must be signed in to change notification settings - Fork 1
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
8-wkdghdwns199 #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ.. μ λ λ¬Έμ κ·Έλλ‘ μ€μλ κ² μ²λΌ νμλλ° μ€λ³΅ μ½λλ λ§μ΄ μκΈ°κ³ κ·Έλ λ€μ
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val n = br.readLine().toInt()
val students = br.readLine().split(" ").map { it.toInt() }.toMutableList()
val stack = Stack<Int>()
var last = 0
while (stack.isNotEmpty() || students.isNotEmpty()) {
when {
// 곡κ°μ΄ λΉμμ λ
stack.isEmpty() -> {
val student = students.removeFirst()
if (student == last + 1) {
last++
} else {
stack.add(student)
}
continue
}
// μ€μ΄ λΉμμ λ
students.isEmpty() -> {
val student = stack.pop()
if (student == last + 1) {
last++
continue
} else {
println("Sad")
return
}
}
// κ³΅κ° λ§¨ μλ³΄λ€ μ€ μμ¬λ μλ²μ΄ λ ν΄ λ
stack.peek() < students[0] -> {
val student = stack.pop()
if (student == last + 1) {
last++
continue
} else {
println("Sad")
return
}
}
// μ€ μμ¬λ μλ²μ΄ κ³΅κ° λ§¨ λ€ λ³΄λ€ ν΄ λ
else -> {
val student = students.removeFirst()
if (student == last + 1) {
last++
} else {
stack.add(student)
}
continue
}
}
}
println("Nice")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν μ€νμ λ¨μμλμ§ μλμ§λ‘ Nice Sadλ₯Ό ꡬλΆνμ
¨κ΅°μ..
μ λ 무μ§μ±μΌλ‘ λΉκ΅ λλ €λ²λ Έλλ°..
νμ΄ μλ΄€μ΅λλ€
import sys
input = sys.stdin.readline
N = int(input())
line = list(map(int, input().split()))
new_line = []
detour = []
start = 0
for _next in line:
while detour and detour[-1] == start+1:
new_line.append(detour.pop())
start += 1
if _next == start+1:
new_line.append(_next)
start += 1
else:
detour.append(_next)
while detour:
new_line.append(detour.pop())
if new_line == sorted(line):
print("Nice")
else:
print("Sad")
μ€ λ¨Όμ νμ΄λ³΄κ³ 리뷰λ₯Ό λ¬λ €λλ° κ±°μ λΉμ·νκ΅°μ!! from collections import deque
n = int(input())
ticket = deque(list(map(int, input().split())))
nop = []
ticket_num = 1
while ticket :
a = ticket.popleft()
if ticket_num != a:
nop.append(a)
else :
ticket_num = a+1
for i in range(len(nop)):
if ticket_num == nop[-1]:
ticket_num = nop[-1] + 1
nop.pop()
else :
break
if nop:
print("Sad")
else :
print("Nice") |
|
||
while order_list : | ||
if order_list[0] == order: | ||
order_list.pop(0) |
There was a problem hiding this comment.
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μ μ΅λκ°μ΄ ν¬λ©΄ μκ°μ΄κ³Όκ° 걸릴 κ² κ°μμ
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/12789
λ¬Έμ
μΈνλνκ΅ νμνμμλ μ€κ°, κΈ°λ§κ³ μ¬ λλ§λ€ μν 곡λΆμ μ§μΉ νμ°λ€μ μν΄ κ°μμ λλ μ£Όλ κ°μ λ리미 νμ¬λ₯Ό μ€μνλ€. μΉνμ΄λ μν κΈ°κ°μ΄ λ λλ§λ€ κ°μμ λ°μ μκ°μ λκ·Όλκ·Ό μ€λ μ μν 곡λΆμ μ§μ€μ λͺ» νλ€. μ΄λ² μ€κ°κ³ μ¬μμλ μμ μΉνμ΄λ μ€λ λ κ°μ΄μ μκ³ κ°μμ λ°κΈ° μν΄ λ―Έλ¦¬ 곡μ§λ μ₯μμ μκ° λ§μΆ° λμ°©νλ€. κ·Έλ°λ° μ΄κ² λ¬΄μ¨ λ λ²Όλ½μΈκ°! κ·Έ κ³³μλ μ΄λ―Έ λͺ¨λ νμλ€μ΄ λͺ¨μ¬μμκ³ , μΉνμ΄λ λ§μ§λ§ λ²νΈνλ₯Ό λ°κ² λμλ€. μ€μκ°μμΌλ‘ λͺλͺ μμ¬μ νΈμ΄ λ νμλ€μ΄ μμΉκΈ°λ₯Ό κ±°λν λμ λκΈ°μ΄μ μμλ§μ μλ§μ΄ λκ³ λ§μλ€. κ°μμ λλ μ£Όκ³ μλ μΈκ·λ νμ°λ€μ ν°μ Έ λμ€λ λΆλ§μ λ²νΈν μμλ‘λ§ κ°μμ μ€ μ μλ€κ³ λ§νλ€.
κ·Έμ μΌ νμλ€μ΄ μμλλ‘ μ€μ μλ €κ³ νμ§λ§ 곡κ°μ΄ λ무 νμν΄μ λ§μλλ‘ μ΄λν μ μμλ€. λ€ννλ λκΈ°μ΄μ μΌμͺ½μλ 1μ΄λ‘ μ€ μ μλ 곡κ°μ΄ μ‘΄μ¬νμ¬ μ΄ κ³΅κ°μ μ μ΄μ©νλ©΄ λͺ¨λκ° μμλλ‘ κ°μμ λ°μ μ μμμ§λ λͺ¨λ₯Έλ€. μμΉ« κ°μμ λͺ» λ°κ² λ μ§λ λͺ¨λ₯Έλ€λ μκΈ°κ°μ λλ μΉνμ΄λ μμ μ μ»΄ν¨ν° μκ³ λ¦¬μ¦μ μ§μμ νμ©ν΄ κ³Όμ° λͺ¨λ μ¬λλ€μ΄ μμλλ‘ κ°μμ λ°μ μ μλμ§ νμΈνλ νλ‘κ·Έλ¨μ λ§λ€κΈ°λ‘ νλ€. λ§μ½ λΆκ°λ₯ νλ€λ©΄ μΉνμ΄λ μ΄λ² μ€κ°κ³ μ¬λ₯Ό λ§μΉκ² λ κ² μ΄κ³ κ°λ₯νλ€λ©΄ νμ μ»μ΄ μ€κ°κ³ μ¬λ₯Ό μ λ³Ό μ μμμ§λ λͺ¨λ₯Έλ€.
μ¬λλ€μ νμ¬ 1μ΄λ‘ μ€μ μμκ³ , 맨 μμ μ¬λλ§ μ΄λμ΄ κ°λ₯νλ€. μΈκ·λ λ²νΈν μμλλ‘λ§ ν΅κ³Όν μ μλ λΌμΈμ λ§λ€μ΄ λμλ€. μ΄ λΌμΈκ³Ό λκΈ°μ΄μ 맨 μ μ¬λ μ¬μ΄μλ ν μ¬λμ© 1μ΄μ΄ λ€μ΄κ° μ μλ 곡κ°μ΄ μλ€. νμ¬ λκΈ°μ΄μ μ¬λλ€μ μ΄ κ³΅κ°μΌλ‘ μ¬ μ μμ§λ§ λ°λλ λΆκ°λ₯νλ€. μΉνμ΄λ₯Ό λμ νλ‘κ·Έλ¨μ μμ±νλΌ.
νμ¬ κ°μ λ°°λΆ κ³΅κ°μ κ·Έλ¦ΌμΌλ‘ λνλ΄λ©΄ λ€μκ³Ό κ°λ€.
μ μμ λ λ€μ κ·Έλ¦Όκ³Ό κ°μ΄ μμ§μμ λ λͺ¨λκ° μμλλ‘ κ°μμ λ°μ μ μλ€..
μ λ ₯
μ λ ₯μ 첫째 μ€μλ νμ¬ μΉνμ΄μ μμ μ μλ νμλ€μ μ N(1 β€ N β€ 1,000,μμ°μ)μ΄ μ£Όμ΄μ§λ€.
λ€μ μ€μλ μΉνμ΄ μμ μμλ λͺ¨λ νμλ€μ λ²νΈν(1,2,...,N) μμκ° μμμλΆν° λ€ μμλ‘ μ£Όμ΄μ§λ€.
μΆλ ₯
μΉνμ΄κ° 무μ¬ν κ°μμ λ°μ μ μμΌλ©΄ "Nice"(λ°μ΄νλ μ μΈ)λ₯Ό μΆλ ₯νκ³ κ·Έλ μ§ μλ€λ©΄ "Sad"(λ°μ΄νλ μ μΈ)λ₯Ό μΆλ ₯νλ€.
μμ μ λ ₯ 1
5
5 4 1 3 2
μμ μΆλ ₯ 1
Nice
βοΈ μμλ μκ°
1μκ° - μ μ€νμΌλ‘λ§ μ λλκ±°μ§..? λ¬Έμ λ₯Ό μλͺ» μ΄ν΄νκ³ μλ?
β¨ μλ μ½λ
μμΉκΈ° ν μΉκ΅¬λ€μ μ€νμ λ¨Όμ λ°μ΄λ£κ³ 1λ²λΆν° κ°μμ λ°κ² ν λ€μ, μ€νμ μλ μΉκ΅¬λ€μ λΉΌλ΄μ£Όλ €κ³ νλλ° μκ°μ΄κ³Όκ° λ΄μ΅λλ€!
μκ°μ΄κ³Όκ° λλ μ½λ [μ λ¬λμ§ μμκ² μΌλ©΄ λ°λ‘ λκΈ λ¬μμ£ΌμΈμ.. γ γ ]
ν΄κ²° : μμλ₯Ό μ§μΉνλ λ³μ order λ₯Ό μ΅μ ν μν€μ§ μμμ 무ν루νμ λΉ μ§ λ¬Έμ μμ΅λλ€!
π μλ‘κ² μκ²λ λ΄μ©