Skip to content
Closed
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
97 changes: 97 additions & 0 deletions hyeokbini/3020.๊ฐœ๋˜ฅ๋ฒŒ๋ ˆ/3020.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include <bits/stdc++.h>

using namespace std;

// ์ข…์œ ์„
vector<int> top;
// ์„์ˆœ
vector<int> 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;
}
1 change: 1 addition & 0 deletions hyeokbini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)|