Skip to content
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

31-9kyo-hwang #120

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <vector>
#include <string>
#include <tuple>

using namespace std;

const vector<tuple<int, int, char>> Offset = {{1, 0, 'd'}, {0, -1, 'l'}, {0, 1, 'r'}, {-1, 0, 'u'}};
vector<vector<vector<bool>>> Visited;

bool OutOfBound(const int n, const int m, int InX, int InY)
{
return InX < 1 || InX > n || InY < 1 || InY > m;
}

string Answer = "";
void DFS(const int n, const int m, const int r, const int c, int InX, int InY, int Remain, string Path = "")
{
if(Remain == 0)
{
if(InX == r && InY == c)
{
Answer = Path;
}
return;
}

Visited[Remain][InX][InY] = true;
for(const auto& [Dx, Dy, Dp] : Offset)
{
int Nx = InX + Dx, Ny = InY + Dy;
string NextPath = Path + Dp;
int NextRemain = Remain - 1;

if(!OutOfBound(n, m, Nx, Ny) && !Visited[NextRemain][Nx][Ny])
{
DFS(n, m, r, c, Nx, Ny, NextRemain, NextPath);
}

if(!Answer.empty())
{
break;
}
}
}

string solution(int n, int m, int x, int y, int r, int c, int k)
{
Visited.assign(k + 1, vector(n + 1, vector(m + 1, false)));
DFS(n, m, r, c, x, y, k);
return Answer.empty() ? "impossible" : Answer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ int main()
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;
Expand All @@ -34,7 +34,7 @@ int main()
}
}
};

Move();

for(int Floor = 1; Floor <= N; ++Floor)
Expand All @@ -43,25 +43,25 @@ int main()
{
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)
{
Expand Down
1 change: 1 addition & 0 deletions 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
| 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) |
| 31์ฐจ์‹œ | 2024.2.29 | Greddy | [๋ฏธ๋กœ ํƒˆ์ถœ ๋ช…๋ น์–ด](https://school.programmers.co.kr/learn/courses/30/lessons/150365) | [#120](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/120) |