From 593d21f3bae9c95635c5cc5160a9c5a58e7db500 Mon Sep 17 00:00:00 2001 From: kwh0420 <143983378+kwh0420@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:00:55 +0900 Subject: [PATCH 1/5] Update 9665.cpp --- Appendix E/solutions/9665.cpp | 56 ++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/Appendix E/solutions/9665.cpp b/Appendix E/solutions/9665.cpp index 6c991660..fa54d3c7 100644 --- a/Appendix E/solutions/9665.cpp +++ b/Appendix E/solutions/9665.cpp @@ -1,11 +1,53 @@ -// Authored by : BaaaaaaaaaaarkingDog +// Authored by : kwh0420 // Co-authored by : - -// http://boj.kr/**************** +// http://boj.kr/c7ea698f2efe4d9ba0fed958631073e5 #include using namespace std; -int main(void){ - ios::sync_with_stdio(0); - cin.tie(0); - -} \ No newline at end of file +string string1; +string string2; +map dna; // 각 유전자의 삽입 비용을 저장하는 매핑 +int A, C, G, T; // 각 유전자의 삽입 비용 +int idx; // 탐색용 인덱스 +int total; // string2 전체를 구성하는 데 필요한 총 비용 +int maxval; // string1 내에서 string2의 연속 부분 문자열과 일치하는 부분 중, 가장 큰 비용 합 + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + cin >> string1; + cin >> string2; + + cin >> A >> C >> G >> T; + + // 유전자 비용 매핑 + dna['A'] = A; + dna['C'] = C; + dna['G'] = G; + dna['T'] = T; + + // string2 전체를 만드는 데 드는 총 비용 계산 + for (int i = 0; i < string2.length(); i++) { + total += dna[string2[i]]; + } + + // string1의 모든 연속 부분 문자열을 확인하면서, + // string2의 부분 문자열이 될 수 있는 경우의 비용 합을 구함 + while (idx < string1.length()) { + int sum = 0; + int temp = idx; + for (int j = 0; j < string2.length(); j++) { + if (string1[idx] == string2[j]) { + sum += dna[string1[idx]]; + idx++; + } + } + idx = temp + 1; + maxval = max(maxval, sum); + } + + // string2 전체 비용에서 이미 string1에 포함된 부분 문자열의 최대 비용을 빼면 + // 추가로 투자해야 할 최소 비용이 됨 + cout << total - maxval; +} From b779dd83327d4eeda204cc1b3a85b80899d01259 Mon Sep 17 00:00:00 2001 From: kwh0420 <143983378+kwh0420@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:01:51 +0900 Subject: [PATCH 2/5] Update Appendix E.md --- workbook/Appendix E.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workbook/Appendix E.md b/workbook/Appendix E.md index 51818c70..5731843f 100644 --- a/workbook/Appendix E.md +++ b/workbook/Appendix E.md @@ -18,7 +18,7 @@ | 기본 문제✔ | 1699 | [제곱수의 합](https://www.acmicpc.net/problem/1699) | [정답 코드](../Appendix%20E/solutions/1699.cpp) | | 기본 문제✔ | 9657 | [돌 게임 3](https://www.acmicpc.net/problem/9657) | [정답 코드](../Appendix%20E/solutions/9657.cpp) | | 기본 문제✔ | 11660 | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [정답 코드](../Appendix%20E/solutions/11660.cpp) | -| 기본 문제✔ | 9665 | [GMO](https://www.acmicpc.net/problem/9665) | - | +| 기본 문제✔ | 9665 | [GMO](https://www.acmicpc.net/problem/9665) | - | [정답 코드](../Appendix%20E/solutions/9665.cpp) | | 기본 문제✔ | 2011 | [암호코드](https://www.acmicpc.net/problem/2011) | [정답 코드](../Appendix%20E/solutions/2011.cpp) | | 기본 문제✔ | 12784 | [인하니카 공화국](https://www.acmicpc.net/problem/12784) | - | | 기본 문제✔ | 25515 | [트리 노드 합의 최댓값](https://www.acmicpc.net/problem/25515) | - | From 41d4331a9338497316abfab56d60afac24f550d9 Mon Sep 17 00:00:00 2001 From: kwh0420 <143983378+kwh0420@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:02:08 +0900 Subject: [PATCH 3/5] Update Appendix E.md --- workbook/Appendix E.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workbook/Appendix E.md b/workbook/Appendix E.md index 5731843f..c28bee96 100644 --- a/workbook/Appendix E.md +++ b/workbook/Appendix E.md @@ -18,7 +18,7 @@ | 기본 문제✔ | 1699 | [제곱수의 합](https://www.acmicpc.net/problem/1699) | [정답 코드](../Appendix%20E/solutions/1699.cpp) | | 기본 문제✔ | 9657 | [돌 게임 3](https://www.acmicpc.net/problem/9657) | [정답 코드](../Appendix%20E/solutions/9657.cpp) | | 기본 문제✔ | 11660 | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [정답 코드](../Appendix%20E/solutions/11660.cpp) | -| 기본 문제✔ | 9665 | [GMO](https://www.acmicpc.net/problem/9665) | - | [정답 코드](../Appendix%20E/solutions/9665.cpp) | +| 기본 문제✔ | 9665 | [GMO](https://www.acmicpc.net/problem/9665) | [정답 코드](../Appendix%20E/solutions/9665.cpp) | | 기본 문제✔ | 2011 | [암호코드](https://www.acmicpc.net/problem/2011) | [정답 코드](../Appendix%20E/solutions/2011.cpp) | | 기본 문제✔ | 12784 | [인하니카 공화국](https://www.acmicpc.net/problem/12784) | - | | 기본 문제✔ | 25515 | [트리 노드 합의 최댓값](https://www.acmicpc.net/problem/25515) | - | From 1a5d24383d1de4e2b214dbd12ce7bc48ddc0ece3 Mon Sep 17 00:00:00 2001 From: kwh0420 <143983378+kwh0420@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:06:03 +0900 Subject: [PATCH 4/5] Update 9665.cpp --- Appendix E/solutions/9665.cpp | 72 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/Appendix E/solutions/9665.cpp b/Appendix E/solutions/9665.cpp index fa54d3c7..66a881de 100644 --- a/Appendix E/solutions/9665.cpp +++ b/Appendix E/solutions/9665.cpp @@ -13,41 +13,41 @@ int total; // string2 전체를 구성하는 데 필요한 총 비용 int maxval; // string1 내에서 string2의 연속 부분 문자열과 일치하는 부분 중, 가장 큰 비용 합 int main() { - ios::sync_with_stdio(0); - cin.tie(0); - - cin >> string1; - cin >> string2; - - cin >> A >> C >> G >> T; - - // 유전자 비용 매핑 - dna['A'] = A; - dna['C'] = C; - dna['G'] = G; - dna['T'] = T; - - // string2 전체를 만드는 데 드는 총 비용 계산 - for (int i = 0; i < string2.length(); i++) { - total += dna[string2[i]]; + ios::sync_with_stdio(0); + cin.tie(0); + + cin >> string1; + cin >> string2; + + cin >> A >> C >> G >> T; + + // 유전자 비용 매핑 + dna['A'] = A; + dna['C'] = C; + dna['G'] = G; + dna['T'] = T; + + // string2 전체를 만드는 데 드는 총 비용 계산 + for (int i = 0; i < string2.length(); i++) { + total += dna[string2[i]]; + } + + // string1의 모든 연속 부분 문자열을 확인하면서, + // string2의 부분 문자열이 될 수 있는 경우의 비용 합을 구함 + while (idx < string1.length()) { + int sum = 0; + int temp = idx; + for (int j = 0; j < string2.length(); j++) { + if (string1[idx] == string2[j]) { + sum += dna[string1[idx]]; + idx++; + } } - - // string1의 모든 연속 부분 문자열을 확인하면서, - // string2의 부분 문자열이 될 수 있는 경우의 비용 합을 구함 - while (idx < string1.length()) { - int sum = 0; - int temp = idx; - for (int j = 0; j < string2.length(); j++) { - if (string1[idx] == string2[j]) { - sum += dna[string1[idx]]; - idx++; - } - } - idx = temp + 1; - maxval = max(maxval, sum); - } - - // string2 전체 비용에서 이미 string1에 포함된 부분 문자열의 최대 비용을 빼면 - // 추가로 투자해야 할 최소 비용이 됨 - cout << total - maxval; + idx = temp + 1; + maxval = max(maxval, sum); + } + + // string2 전체 비용에서 이미 string1에 포함된 부분 문자열의 최대 비용을 빼면 + // 추가로 투자해야 할 최소 비용이 됨 + cout << total - maxval; } From 0588db99bb79bba3a3338699b33d84d3b07e573f Mon Sep 17 00:00:00 2001 From: kwh0420 <143983378+kwh0420@users.noreply.github.com> Date: Fri, 22 Aug 2025 20:18:33 +0900 Subject: [PATCH 5/5] Update 9665.cpp --- Appendix E/solutions/9665.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Appendix E/solutions/9665.cpp b/Appendix E/solutions/9665.cpp index 66a881de..f6a23da3 100644 --- a/Appendix E/solutions/9665.cpp +++ b/Appendix E/solutions/9665.cpp @@ -28,9 +28,9 @@ int main() { dna['T'] = T; // string2 전체를 만드는 데 드는 총 비용 계산 - for (int i = 0; i < string2.length(); i++) { + for (int i = 0; i < string2.length(); i++) total += dna[string2[i]]; - } + // string1의 모든 연속 부분 문자열을 확인하면서, // string2의 부분 문자열이 될 수 있는 경우의 비용 합을 구함