From 07248bc5b3a98a187f71c0877dd6b85591253db4 Mon Sep 17 00:00:00 2001 From: Yeonsoo <127713796+sooooscode@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:35:44 +0900 Subject: [PATCH 1/5] Create 10815.cpp --- .../10815.cpp" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" new file mode 100644 index 0000000..6347f64 --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/10815.cpp" @@ -0,0 +1,42 @@ +//10_이분탐색 필수1: 10815 + +#include +#include + +using namespace std; + +int n, m; +int arr[500000]; + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(NULL); + + cin >> n; + + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + + // 숫자 카드 오름차순 정렬 + sort(arr, arr + n); + + cin >> m; + + for (int i = 0; i < m; i++) + { + int num; + cin >> num; + + // 이분 탐색: 해당 숫자가 있는 경우 + if (binary_search(arr, arr + n, num)) + { + cout << "1 "; + } else { + cout << "0 "; + } + } + + return 0; +} From c70d21207b27d97fe5e788040a409a681f64d7f5 Mon Sep 17 00:00:00 2001 From: Yeonsoo <127713796+sooooscode@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:39:23 +0900 Subject: [PATCH 2/5] Create 14500.cpp --- .../14500.cpp" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "10_\354\235\264\353\266\204\355\203\220\354\203\211/14500.cpp" diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/14500.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/14500.cpp" new file mode 100644 index 0000000..4195525 --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/14500.cpp" @@ -0,0 +1,87 @@ +//10_이분탐색 필수2: 14500 + +#include +#include + +using namespace std; + +int n, m, ans; +vector> map; +vector> visit; +vector dy = {-1, 1, 0, 0}; +vector dx = {0, 0, -1, 1}; + +void dfs(int y, int x, int cnt, int sum, vector>& visit) +{ + if (cnt >= 4) + { + ans = max(ans, sum); + return; + } + + for (int k = 0; k < 4; k++) + { + int ny = y + dy[k]; + int nx = x + dx[k]; + + if (ny < 0 || nx < 0 || ny >= n || nx >= m || visit[ny][nx]) { + continue; + } + + visit[ny][nx] = true; + dfs(ny, nx, cnt + 1, sum + map[ny][nx], visit); + visit[ny][nx] = false; + } +} + +void check(int y, int x) +{ + if (y < n - 2 && x < m - 1){ + ans = max(ans, map[y][x] + map[y + 1][x] + map[y + 2][x] + map[y + 1][x + 1]); + } + + if (y < n - 2 && x > 0){ + ans = max(ans, map[y][x] + map[y + 1][x] + map[y + 2][x] + map[y + 1][x - 1]); + } + + if (y < n - 1 && x < m - 2){ + ans = max(ans, map[y][x] + map[y][x + 1] + map[y][x + 2] + map[y + 1][x + 1]); + } + + if (y > 0 && x < m - 2){ + ans = max(ans, map[y][x] + map[y][x + 1] + map[y][x + 2] + map[y - 1][x + 1]); + } +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(NULL); + + cin >> n >> m; + map.assign(n, vector(m)); + visit.assign(n, vector(m, false)); + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < m; j++) { + cin >> map[i][j]; + } + } + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < m; j++) + { + visit[i][j] = true; + dfs(i, j, 1, map[i][j], visit); + + visit[i][j] = false; + check(i, j); + } + } + + cout << ans << "\n"; + + return 0; +} From 09e6aa74d5c264c131d11fa76a0324c51cf6ab86 Mon Sep 17 00:00:00 2001 From: Yeonsoo <127713796+sooooscode@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:41:40 +0900 Subject: [PATCH 3/5] Create 16401.cpp --- .../16401.cpp" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" new file mode 100644 index 0000000..6a70d70 --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/16401.cpp" @@ -0,0 +1,53 @@ +//10_이분탐색 필수3: 16401 + +#include +#include +#include + +using namespace std; + +int m, n, result; +vector arr; + +void bs(int s, int e) +{ + if (s > e) + return; + int mid = (s + e) / 2; + int cnt = 0; + + for (int i = 0; i < n; i++) + cnt += arr[i] / mid; + + if (cnt >= m) + { + if (result < mid){ + result = mid; + } + bs(mid + 1, e); + } + else { + bs(s, mid - 1); + } +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(NULL); + + cin >> m >> n; + arr.resize(n); + + for (int i = 0; i < n; i++){ + cin >> arr[i]; + } + + sort(arr.begin(), arr.end()); + + bs(1, arr[n - 1]); + + cout << result << "\n"; + + return 0; +} From e19fc2c6e5c27adc9d1eaeb91a4a79c83335a038 Mon Sep 17 00:00:00 2001 From: Yeonsoo <127713796+sooooscode@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:43:08 +0900 Subject: [PATCH 4/5] Create 2343.cpp --- .../2343.cpp" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "10_\354\235\264\353\266\204\355\203\220\354\203\211/2343.cpp" diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/2343.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/2343.cpp" new file mode 100644 index 0000000..1afa787 --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/2343.cpp" @@ -0,0 +1,50 @@ +//10_이분탐색 도전1: 2343 + +#include +#include +#include + +using namespace std; + +int main() +{ + int n, m; + cin >> n >> m; + + vector lengths(n); + + for (int i = 0; i < n; i++) { + cin >> lengths[i]; + } + + int left = *max_element(lengths.begin(), lengths.end()); + int right = 10000 * n; // 최대 블루레이 크기 + + while (left < right) + { + int mid = (left + right) / 2; + int count = 1; // 블루레이 개수 + int sum = 0; // 현재 녹화된 길이 + + for (int i = 0; i < n; i++) + { + if (sum + lengths[i] > mid) + { + count++; + sum = 0; + } + sum += lengths[i]; + } + + if (count <= m) { + right = mid; + } + else { + left = mid + 1; + } + } + + cout << left << "\n"; + + return 0; +} From 1f5ab1e665795609bc5da0a18a278123a317954b Mon Sep 17 00:00:00 2001 From: Yeonsoo <127713796+sooooscode@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:44:11 +0900 Subject: [PATCH 5/5] Create 3079.cpp --- .../3079.cpp" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "10_\354\235\264\353\266\204\355\203\220\354\203\211/3079.cpp" diff --git "a/10_\354\235\264\353\266\204\355\203\220\354\203\211/3079.cpp" "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/3079.cpp" new file mode 100644 index 0000000..21e7102 --- /dev/null +++ "b/10_\354\235\264\353\266\204\355\203\220\354\203\211/3079.cpp" @@ -0,0 +1,58 @@ +//10_이분탐색 도전2: 3079 + +#include +#include + +using namespace std; + +long long MIN_TIME = 1; +long long MAX_TIME = 1000000000LL * 1000000000LL; + +bool checkInTime(vector& input, int n, int m, long long time) +{ + long long peopleCnt = 0; + for (int i = 0; i < n; i++) + { + peopleCnt += (time / input[i]); + if (peopleCnt >= m) { + return true; + } + } + return false; +} + +long long binarySearch(vector& input, int n, int m) +{ + long long result = MAX_TIME; + long long start = MIN_TIME; + long long end = MAX_TIME; + + while (start <= end) { + long long mid = (start + end) / 2; + if (checkInTime(input, n, m, mid)) + { + end = mid - 1; + result = mid; + } + else { + start = mid + 1; + } + } + return result; +} + +int main() +{ + int n, m; + cin >> n >> m; + vector input(n); + + for (int i = 0; i < n; i++) { + cin >> input[i]; + } + + long long answer = binarySearch(input, n, m); + cout << answer << ""\n; + + return 0; +}