Skip to content

Commit

Permalink
30-9kyo-hwang
Browse files Browse the repository at this point in the history
  • Loading branch information
9kyo-hwang committed Feb 26, 2024
1 parent 513981e commit a85020f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <iostream>
#include <vector>

using namespace std;

int main()
{
cin.tie(nullptr)->sync_with_stdio(false);

int N; cin >> N;

vector<int> A(N + 1, 0), NumToComeHere(N + 1, 0);
vector<bool> IsOutOfHere(N + 1, false);

for(int i = 1; i <= N; ++i)
{
cin >> A[i];
NumToComeHere[A[i]] += 1;
}

vector<int> 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;
}
1 change: 1 addition & 0 deletions 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

0 comments on commit a85020f

Please sign in to comment.