diff --git "a/hyeokbini/3020.\352\260\234\353\230\245\353\262\214\353\240\210/3020.cpp" "b/hyeokbini/3020.\352\260\234\353\230\245\353\262\214\353\240\210/3020.cpp" new file mode 100644 index 0000000..bdbc055 --- /dev/null +++ "b/hyeokbini/3020.\352\260\234\353\230\245\353\262\214\353\240\210/3020.cpp" @@ -0,0 +1,97 @@ +#include + +using namespace std; + +// 종유석 +vector top; +// 석순 +vector bottom; +int n, h; +int best = INT_MAX; +int way = 0; + +// 인자로 주는 curheight는 0 based로 +void func(int curheight) +{ + int val = 0; + int needbottom = curheight + 1; + int needtop = h - curheight; + + // 석순 계산 + int start = 0; + int end = (n / 2) - 1; + int stand = n / 2; // 기본값 + while(start <= end) + { + int mid = (start + end) / 2; + if(bottom[mid] >= needbottom) + { + stand = mid; + end = mid - 1; + } + else + { + start = mid + 1; + } + } + val += (n / 2) - stand; + // 종유석 계산 + start = 0; + end = (n / 2) - 1; + stand = n / 2; + while(start <= end) + { + int mid = (start + end) / 2; + if(top[mid] >= needtop) + { + stand = mid; + end = mid - 1; + } + else + { + start = mid + 1; + } + } + val += (n/2) - stand; + + // 갱신 + if(best > val) + { + best = val; + way = 1; + } + else if(best == val) + { + way++; + } + return; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(0); + //freopen("test.txt", "rt", stdin); + cin >> n >> h; + for(int i = 0; i < n; i++) + { + int val; + cin >> val; + if(i % 2 == 0) + { + bottom.push_back(val); + } + else + { + top.push_back(val); + } + } + sort(bottom.begin(),bottom.end()); + sort(top.begin(),top.end()); + for(int i = 0; i < h; i++) + { + func(i); + } + cout << best << " " << way; + return 0; +} diff --git a/hyeokbini/README.md b/hyeokbini/README.md index 182728a..19e50ba 100644 --- a/hyeokbini/README.md +++ b/hyeokbini/README.md @@ -23,3 +23,4 @@ | 19차시 | 2025.08.10 | 브루트포스 | [리모컨](https://www.acmicpc.net/problem/1107)|[#19](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/68)| | 20차시 | 2025.08.14 | 완전탐색,DFS | [모음사전](https://school.programmers.co.kr/learn/courses/30/lessons/84512)|[#20](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/72)| | 21차시 | 2025.08.19 | 브루트포스 | [제곱수 찾기](https://www.acmicpc.net/problem/1025)|[#21](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/76)| + | 23차시 | 2025.08.27 | 이분 탐색 | [개똥벌레](https://www.acmicpc.net/problem/3020)|[#23](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/80)| \ No newline at end of file