-
Notifications
You must be signed in to change notification settings - Fork 2
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
1-Dolchae #2
1-Dolchae #2
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.
κ³ μ λ§μμ΅λλ€!
μ€λ² 2 λμ΄λλΌ κ½€ μ΄λ €μ μ ν
λ° 1μκ°λμ λμ§κΈ°κ² λΆμ‘μλ€λ... μ΄λ―Έ μμ 1%μ
λλ€ π
while cur <= input_num: | ||
stack.append(cur) | ||
ans.append("+") | ||
cur += 1 | ||
|
||
if stack[-1] == input_num: | ||
stack.pop() | ||
ans.append("-") |
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.
μ λ μ΄μ μ λ¬Έμ λ₯Ό νμμλλ°, λ¬Έμ (λ λμκ° μ€ν)μμ μλν λλ‘ μ νΈμ κ² κ°μ΅λλ€!
μ μ κ²½μ°μλ μμ΄μ λ¨Όμ μ μ₯ν΄λκ³ , 1λΆν° nκΉμ§ μ«μλ₯Ό λ£μΌλ©΄μ κ·Έ λλ§λ€ μμ΄μ λ€μ νμΈν΄ νΈλ μμΌλ‘ νκ±°λ μ.
vector<int> sequence(n);
for (int& i : sequence)
cin >> i;
vector<int> stack;
vector<char> operators;
for (int i = 1; i <= n; i++) {
stack.emplace_back(i);
operators.emplace_back('+');
while (!stack.empty() && stack.back() == sequence.front()) {
stack.pop_back();
operators.emplace_back('-');
sequence.erase(sequence.begin());
}
}
- 1λΆν° nκΉμ§ μ«μλ₯Ό μ€νμ νλμ© λ£κ³ , κ·Έ λλ§λ€ μ μ₯λ μμ΄μ μμμλΆν° νμΈν΄ μΌμΉνλ μ«μκ° μμ λκΉμ§ stackκ³Ό sequenceμμ κ·Έ μ«μλ₯Ό μμ λ μμΌλ‘ μννμ£ .
- λ€ λμμ λ μ€νμ λ¨μμλ μ«μκ° μλ€λ©΄ λ§λ€ μ μλ μμ΄μ΄λΌ νλ¨νλ μμΌλ‘ λ§μ΄μ£ .
ans.append("-") | ||
else: | ||
k = 0 | ||
if k==1: |
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.
kλ₯Ό μ΄μ©ν΄ ν΄λΉ μμ΄μ λ§λ€ μ μλ μ§ μλ μ§λ₯Ό ꡬλΆμ§λλ°, κ·Έλ° μ©λλΌλ©΄ boolean λ³μλ₯Ό μ΄μ©νλ κ²μ΄ μ’ λ μ§κ΄μ μ΄μ§ μμκΉμ?
μλ₯Ό λ€μ΄
isPossibleSequence = True
...
else:
isPossibleSequence = False
break
μ΄λ° μμΌλ‘ νλ©΄ λμ ν λ€μ΄μ€κ² μ£ ? λν λΆκ°λ₯ν μμ΄μμ΄ νμΈλ μκ° μ¦μ break ν΄μ£Όλ©΄ μ‘°κΈ λ ν¨μ¨μ μΌ κ² κ°λ€μ!
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.
.
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.
λ¬Έμ κ° μ΄ν΄κ° μ μλμ΄μ μ€λ κ±Έλ¦¬κ³ μ΄λ €μ λ€μ...
μ€λͺ
μ 보λ μ΄ν΄κ° μ λμμ΅λλ€!
μκ³ νμ
¨μ΅λλ€!!ππ
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/1874
βοΈ μμλ μκ°
1μκ°
β¨ μλ μ½λ
λ¬Έμ μ€λͺ
- λ¬Έμ λ₯Ό μ΄ν΄νλ λ°μ μ‘°κΈ μ΄λ €μμ΄ μμλλ°, μ΄ λ¬Έμ 쑰건μ ν΅μ¬μ μ€νμ pushν λ λ°λμ 'μ€λ¦μ°¨μ'μΌλ‘λ§ κ°λ₯νλ€λ κ²μ΄λ€. μλ₯Ό λ€μ΄ 3μ pushνκ³ μΆλ€λ©΄ 1,2,3μ΄ μ€ν μμ μμ΄μΌ νλ€. - λ λ€λ₯Έ 쑰건μ popλλ μμκ° μ λ ₯λ μμμ κ°μμΌ νλ€λ κ²μ΄λ€.
μ½λ μ€λͺ
- μ 체 μ½λμ λλ€.
π μλ‘κ² μκ²λ λ΄μ©
https://www.youtube.com/watch?v=WB_BoAgWLNU