From 7eaf940f660efe97376eb40d527ff53d0b47afea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Fri, 29 Mar 2024 22:13:13 +0900 Subject: [PATCH 1/4] =?UTF-8?q?13=EC=B0=A8=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13\354\260\250\354\213\234 - BOJ 7569.cpp" | 50 +++++++++++++++++++ YIM2UL2ET/README.md | 1 + 2 files changed, 51 insertions(+) create mode 100644 "YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" diff --git "a/YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" "b/YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" new file mode 100644 index 0000000..4db562f --- /dev/null +++ "b/YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" @@ -0,0 +1,50 @@ +#include +#include +#include + +struct idx {int z, y, x;}; + +int main(void) +{ + std::ios_base::sync_with_stdio(false); + std::cin.tie(NULL); + + int m, n, h, res = 0, non = 0; + std::vector offset = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}}; + std::queue que[2]; + bool curQueue = false; + + std::cin >> n >> m >> h; + int box[h][m][n]; + + for (int z = 0; z < h; z++) { + for (int y = 0; y < m; y++) { + for (int x = 0; x < n; x++) { + std::cin >> box[z][y][x]; + if (box[z][y][x] == 1) que[curQueue].push({z, y, x}); + else if (box[z][y][x] == 0) non++; + } + } + } + + while (!que[curQueue].empty() && non > 0) { + while (!que[curQueue].empty()) { + int z = que[curQueue].front().z, y = que[curQueue].front().y, x = que[curQueue].front().x; + for (idx set : offset) { + int zz = z + set.z, yy = y + set.y, xx = x + set.x; + if (zz >= 0 && zz < h && yy >= 0 && yy < m && xx >= 0 && xx < n && box[zz][yy][xx] == 0) { + box[zz][yy][xx] = 1, non--; + que[!curQueue].push({zz, yy, xx}); + } + } + que[curQueue].pop(); + } + curQueue = !curQueue; + res++; + } + + if (non > 0) std::cout << -1; + else std::cout << res; + + return 0; +} \ No newline at end of file diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index 32219bb..2431e6c 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.03.10 | 스택 | [BOJ 1406](https://www.acmicpc.net/problem/1406) | [BOJ 1406 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/31) | | 11차시 | 2024.03.18 | 스택 | [BOJ 1918](https://www.acmicpc.net/problem/1918) | [BOJ 1918 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/36) | | 12차시 | 2024.03.28 | 비트마스킹 | [BOJ 11723](https://www.acmicpc.net/problem/11723) | [BOJ 11723 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/39) | +| 13차시 | 2024.04.01 | BFS | [BOJ 7569](https://www.acmicpc.net/problem/7569) | [BOJ 7569 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/42) | --- From d536d12d89e2a9eb5f6395a738198a354e6d3a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:13:51 +0900 Subject: [PATCH 2/4] =?UTF-8?q?14=EC=B0=A8=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YIM2UL2ET/README.md | 1 + ...4\354\260\250\354\213\234 - BOJ 11286.cpp" | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 "YIM2UL2ET/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/14\354\260\250\354\213\234 - BOJ 11286.cpp" diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index 2431e6c..97466af 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -15,4 +15,5 @@ | 11차시 | 2024.03.18 | 스택 | [BOJ 1918](https://www.acmicpc.net/problem/1918) | [BOJ 1918 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/36) | | 12차시 | 2024.03.28 | 비트마스킹 | [BOJ 11723](https://www.acmicpc.net/problem/11723) | [BOJ 11723 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/39) | | 13차시 | 2024.04.01 | BFS | [BOJ 7569](https://www.acmicpc.net/problem/7569) | [BOJ 7569 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/42) | +| 14차시 | 2024.04.04 | 우선순위 큐 | [BOJ 11286](https://www.acmicpc.net/problem/11286) | [BOJ 11286 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/43) | --- diff --git "a/YIM2UL2ET/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/14\354\260\250\354\213\234 - BOJ 11286.cpp" "b/YIM2UL2ET/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/14\354\260\250\354\213\234 - BOJ 11286.cpp" new file mode 100644 index 0000000..43b1864 --- /dev/null +++ "b/YIM2UL2ET/\354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220/14\354\260\250\354\213\234 - BOJ 11286.cpp" @@ -0,0 +1,51 @@ +#include +#include + +void cre_heap(std::vector &heap, int key) { + int k = heap.size(); + heap.push_back(key); + while (k > 1) { + if (abs(heap[k/2]) > abs(heap[k]) || (abs(heap[k/2]) == abs(heap[k]) && heap[k/2] > heap[k])) { + std::swap(heap[k], heap[k/2]); + k /= 2; + } + else break; + } + return; +} + +void del_heap(std::vector &heap) { + int k = 1; + heap[1] = heap.back(), heap.pop_back(); + while (k * 2 <= heap.size()) { + if (k * 2 + 1 < heap.size() && (abs(heap[k*2+1]) < abs(heap[k*2]) || (abs(heap[k*2+1]) == abs(heap[k*2]) && heap[k*2+1] < heap[k*2]))) + k = k*2+1; + else k = k*2; + + if (abs(heap[k/2]) > abs(heap[k]) || (abs(heap[k/2]) == abs(heap[k]) && heap[k/2] > heap[k])) + std::swap(heap[k/2], heap[k]); + else break; + } + return; +} + +int main(void) { + std::ios_base::sync_with_stdio(false); + std::cin.tie(NULL); + std::cout.tie(NULL); + + int n, k, x; + std::vector abs_heap = {0}; + + std::cin >> n; + for (int i = 0; i < n; i++) { + std::cin >> x; + if (abs(x) > 0) cre_heap(abs_heap, x); + else if (abs_heap.size() > 1) { + std::cout << abs_heap[1] << '\n'; + del_heap(abs_heap); + } + else std::cout << 0 << '\n'; + } + +} \ No newline at end of file From 7986fda52385b45b53952274b64ed9cd7b6738d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:01:34 +0900 Subject: [PATCH 3/4] =?UTF-8?q?15=EC=B0=A8=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YIM2UL2ET/README.md | 3 ++- ...5\354\260\250\354\213\234 - BOJ 14719.cpp" | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 "YIM2UL2ET/\352\265\254\355\230\204/15\354\260\250\354\213\234 - BOJ 14719.cpp" diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index 97466af..4ac05c2 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -16,4 +16,5 @@ | 12차시 | 2024.03.28 | 비트마스킹 | [BOJ 11723](https://www.acmicpc.net/problem/11723) | [BOJ 11723 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/39) | | 13차시 | 2024.04.01 | BFS | [BOJ 7569](https://www.acmicpc.net/problem/7569) | [BOJ 7569 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/42) | | 14차시 | 2024.04.04 | 우선순위 큐 | [BOJ 11286](https://www.acmicpc.net/problem/11286) | [BOJ 11286 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/43) | ---- +| 15차시 | 2024.04.09 | 구현 | [BOJ 14719](https://www.acmicpc.net/problem/14719) | [BOJ 14719 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/48) | +--- \ No newline at end of file diff --git "a/YIM2UL2ET/\352\265\254\355\230\204/15\354\260\250\354\213\234 - BOJ 14719.cpp" "b/YIM2UL2ET/\352\265\254\355\230\204/15\354\260\250\354\213\234 - BOJ 14719.cpp" new file mode 100644 index 0000000..9b6e931 --- /dev/null +++ "b/YIM2UL2ET/\352\265\254\355\230\204/15\354\260\250\354\213\234 - BOJ 14719.cpp" @@ -0,0 +1,23 @@ +#include +#include +#include + +int main(void) { + int height, width, res = 0; + + std::cin >> height >> width; + std::vector vec(width); + for (int i = 0; i < width; i++) std::cin >> vec[i]; + + for (int i = height; i >= 0; i--) { + int cnt = std::count_if(vec.begin(), vec.end(), [&i](int v) -> bool {return v>=i;}); + if (cnt > 1) { + int front = std::find_if(vec.begin(), vec.end(), [&i](int v) -> bool {return v>=i;}) - vec.begin(); + int back = std::find_if(vec.rbegin(), vec.rend(), [&i](int v) -> bool {return v>=i;}) - vec.rbegin(); + res += width - back - front - cnt; + } + } + + std::cout << res; + return 0; +} \ No newline at end of file From 2146ac6c299b5f1be0ae3076bd4b1044629a6a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=84=EC=8A=B9=ED=98=B8?= <132066506+YIM2UL2ET@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:00:29 +0900 Subject: [PATCH 4/4] =?UTF-8?q?16=EC=B0=A8=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YIM2UL2ET/README.md | 1 + ...6\354\260\250\354\213\234 - BOJ 15927.cpp" | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 "YIM2UL2ET/\354\225\240\353\223\234 \355\230\271/16\354\260\250\354\213\234 - BOJ 15927.cpp" diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index 4ac05c2..785ddc5 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -17,4 +17,5 @@ | 13차시 | 2024.04.01 | BFS | [BOJ 7569](https://www.acmicpc.net/problem/7569) | [BOJ 7569 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/42) | | 14차시 | 2024.04.04 | 우선순위 큐 | [BOJ 11286](https://www.acmicpc.net/problem/11286) | [BOJ 11286 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/43) | | 15차시 | 2024.04.09 | 구현 | [BOJ 14719](https://www.acmicpc.net/problem/14719) | [BOJ 14719 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/48) | +| 16차시 | 2024.04.09 | 구현 | [BOJ 15927](https://www.acmicpc.net/problem/15927) | [BOJ 15927 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/51) | --- \ No newline at end of file diff --git "a/YIM2UL2ET/\354\225\240\353\223\234 \355\230\271/16\354\260\250\354\213\234 - BOJ 15927.cpp" "b/YIM2UL2ET/\354\225\240\353\223\234 \355\230\271/16\354\260\250\354\213\234 - BOJ 15927.cpp" new file mode 100644 index 0000000..a54da02 --- /dev/null +++ "b/YIM2UL2ET/\354\225\240\353\223\234 \355\230\271/16\354\260\250\354\213\234 - BOJ 15927.cpp" @@ -0,0 +1,22 @@ +#include +#include + +bool isOneChar(std::string str) { + int size = str.size(); + for (int i = 1; i < size; i++) { + if (str[i-1] != str[i]) return false; + } + return true; +} + +int main(void) { + std::string str, rstr; + std::cin >> str, rstr = str; + std::reverse(rstr.begin(), rstr.end()); + + if (isOneChar(str)) std::cout << -1; + else if (str == rstr) std::cout << str.size()-1; + else std::cout << str.size(); + + return 0; +} \ No newline at end of file