728x90
๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/30/lessons/42586#
ํ๋ก๊ทธ๋๋จธ์ค
SW๊ฐ๋ฐ์๋ฅผ ์ํ ํ๊ฐ, ๊ต์ก, ์ฑ์ฉ๊น์ง Total Solution์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ์ฑ์ฅ์ ์ํ ๋ฒ ์ด์ค์บ ํ
programmers.co.kr
ํ๋ก๊ทธ๋๋จธ์ค ๋ ๋ฒจ 2.
์คํ์ ํ์ฉํ์ฌ ํด๊ฒฐํด์ผ ํ๋ค
์ฒ์์ ์ ์ถํ์ ๋ ๋ช๋ช ๊ฐ์ ํ ์คํธ์ผ์ด์ค์์ ์คํจ๊ฐ ๋ด๋๋ฐ,
์๋ ํ ์ผ๋ฅผ ํ์ฉํด์ ํต๊ณผํ ์ ์์๋ค ใ .ใ
์คํ ๋ด๋ถ์ max๊ฐ์ ๊ธฐ์ตํด๋์ด์ผ ํ๋ค!
๋์ ํ์ด
#include <string>
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> progresses, vector<int> speeds) {
vector<int> answer;
int n = progresses.size();
int nowMax = 0;
stack<int> st;
for(int i=0; i<n; ++i){
int left = 100 - progresses[i];
int date = left / speeds[i];
int before = false;
if(left % speeds[i] != 0) date += 1;
// cout << date <<"\n";
if(st.empty()) {
st.push(date);
nowMax = date;
}
else{
int size = st.size();
// top์ด ๋ ํฌ๋ฉด ์คํ์ push
if(nowMax >= date){
st.push(date);
continue;
}
// ๋งจ ์์ ์ซ์๋ณด๋ค ํฌ๋ฉด ๊ธฐ์กด ๋ด์ฉ์ ๋ชจ๋ pop, count
while(!st.empty()){
st.pop();
}
answer.push_back(size);
st.push(date);
nowMax = date;
}
}
if(!st.empty()){
answer.push_back(st.size());
}
return answer;
}
728x90
๋ฐ์ํ
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++/PGS] Lv.3 : ๊ฐ์ฅ ๊ธด ํฐ๋ฆฐ๋๋กฌ (ํฌํฌ์ธํฐ/์ค์ฌํ์ฅ) (0) | 2025.04.25 |
---|---|
[C++/PGS] Lv.2 : ๊ดํธ ํ์ ํ๊ธฐ (0) | 2025.04.23 |
[C++/PGS] Lv.3 : ๋์คํฌ ์ปจํธ๋กค๋ฌ (Heap/priority_queue) (0) | 2025.04.17 |
[C++/PGS] Lv.4 : ํธํ ๋ฐฉ ๋ฐฐ์ (์ฌ๊ท) (0) | 2025.04.16 |
[C++/PGS] Lv.3 : ์๊ณผ ๋๋ (DFS) (0) | 2025.04.15 |