diff --git "a/9-kyo-hwang/Greedy/23296 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260 \354\241\260\354\236\221.cpp" "b/9-kyo-hwang/Greedy/23296 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260 \354\241\260\354\236\221.cpp" new file mode 100644 index 0000000..aeb37eb --- /dev/null +++ "b/9-kyo-hwang/Greedy/23296 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260 \354\241\260\354\236\221.cpp" @@ -0,0 +1,72 @@ +#include +#include + +using namespace std; + +int main() +{ + cin.tie(nullptr)->sync_with_stdio(false); + + int N; cin >> N; + + vector A(N + 1, 0), NumToComeHere(N + 1, 0); + vector IsOutOfHere(N + 1, false); + + for(int i = 1; i <= N; ++i) + { + cin >> A[i]; + NumToComeHere[A[i]] += 1; + } + + vector BtnsToPress; + auto Move = [&](int Floor = 1) + { + while(!IsOutOfHere[Floor]) + { + IsOutOfHere[Floor] = true; + int NextFloor = A[Floor]; + + if(NumToComeHere[NextFloor] > 0) + { + NumToComeHere[NextFloor] -= 1; + BtnsToPress.emplace_back(NextFloor); + Floor = NextFloor; + } + } + }; + + Move(); + + for(int Floor = 1; Floor <= N; ++Floor) + { + if(IsOutOfHere[Floor]) + { + continue; + } + + if(NumToComeHere[Floor] == 0) + { + BtnsToPress.emplace_back(Floor); + Move(Floor); + } + } + + for(int Floor = 1; Floor <= N; ++Floor) + { + if(IsOutOfHere[Floor]) + { + continue; + } + + BtnsToPress.emplace_back(Floor); + Move(Floor); + } + + cout << BtnsToPress.size() << "\n"; + for(const int& Btn : BtnsToPress) + { + cout << Btn << " "; + } + + return 0; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 8b68b69..3b5c703 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -30,3 +30,4 @@ | 27차시 | 2024.2.14 | Graph Traversal | [1039 교환](https://www.acmicpc.net/problem/1039) | [#105](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/105) | | 28차시 | 2024.2.19 | Simulation | [SWEA 5644 무선 충전](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRDL1aeugDFAUo&categoryId=AWXRDL1aeugDFAUo&categoryType=CODE&problemTitle=5644&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1) | [#111](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/111) | | 29차시 | 2024.2.22 | Prefix Sum | [파괴되지 않은 건물](https://school.programmers.co.kr/learn/courses/30/lessons/92344) | [#114](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/114) | +| 30차시 | 2024.2.24 | Greddy | [23296 엘리베이터 조작](https://www.acmicpc.net/problem/23296) | [#115](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/115) |