Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

37-pknujsp #149

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
45 changes: 23 additions & 22 deletions pknujsp/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :--------------------------------------------------------: |
| 1์ฐจ์‹œ | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) |
| 2์ฐจ์‹œ | 2023.10.09 | BRUTE_FORCE | [์—ฐ์† ๋ถ€๋ถ„ ์ˆ˜์—ด ํ•ฉ์˜ ๊ฐœ์ˆ˜](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) |
| 3์ฐจ์‹œ | 2023.10.11 | SORT | [์ตœ์†Ÿ๊ฐ’ ๋งŒ๋“ค๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) |
| 4์ฐจ์‹œ | 2023.10.13 | SORT | [ํŠœํ”Œ](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) |
| 5์ฐจ์‹œ | 2023.10.15 | ๊ตฌํ˜„ | [๊ด„ํ˜ธ ๋ณ€ํ™˜](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) |
| 6์ฐจ์‹œ | 2023.10.17 | ํƒ์ƒ‰ | [์ฟผ๋“œ์••์ถ• ํ›„ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) |
| 7์ฐจ์‹œ | 2023.10.19 | ํƒ์ƒ‰ | [๋ฌด์ธ๋„ ์—ฌํ–‰](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) |
| 8์ฐจ์‹œ | 2023.10.21 | ํƒ์ƒ‰ | [๊ฑฐ๋ฆฌ๋‘๊ธฐ ํ™•์ธํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) |
| 9์ฐจ์‹œ | 2023.10.23 | ๋งต | [์Šคํ‚ฌ ํŠธ๋ฆฌ](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) |
| 10์ฐจ์‹œ | 2023.10.25 | ๊ตฌํ˜„ | [์ˆ˜์‹ ์ตœ๋Œ€ํ™”](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) |
| 11์ฐจ์‹œ | 2023.10.27 | ๋ฆฌ์ŠคํŠธ | [์˜์–ด ๋๋ง์ž‡๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) |
| 12์ฐจ์‹œ | 2023.10.30 | ํ | [์ด์ค‘์šฐ์„ ์ˆœ์œ„ํ](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) |
| 13์ฐจ์‹œ | 2023.11.01 | DP | [๋“ฑ๊ตฃ๊ธธ](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) |
| 14์ฐจ์‹œ | 2023.11.03 | ๋งต | [์‹œ์†Œ ์ง๊ฟ](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) |
| 15์ฐจ์‹œ | 2023.11.05 | ์ˆ˜ํ•™ | [์˜ˆ์ƒ ๋Œ€์ง„ํ‘œ](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) |
| 16์ฐจ์‹œ | 2023.11.08 | ์ˆ˜ํ•™ | [์ˆซ์ž ๋ณ€ํ™˜ํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) |
| 17์ฐจ์‹œ | 2023.11.10 | ์Šคํƒ | [์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) |
| 18์ฐจ์‹œ | 2023.11.13 | ๊ตฌํ˜„ | [ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) |
| 19์ฐจ์‹œ | 2023.11.17 | ๊ตฌํ˜„ | [์‹คํŒจ์œจ](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) |
| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :---------------------------------------------------------: |
| 1์ฐจ์‹œ | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) |
| 2์ฐจ์‹œ | 2023.10.09 | BRUTE_FORCE | [์—ฐ์† ๋ถ€๋ถ„ ์ˆ˜์—ด ํ•ฉ์˜ ๊ฐœ์ˆ˜](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) |
| 3์ฐจ์‹œ | 2023.10.11 | SORT | [์ตœ์†Ÿ๊ฐ’ ๋งŒ๋“ค๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) |
| 4์ฐจ์‹œ | 2023.10.13 | SORT | [ํŠœํ”Œ](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) |
| 5์ฐจ์‹œ | 2023.10.15 | ๊ตฌํ˜„ | [๊ด„ํ˜ธ ๋ณ€ํ™˜](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) |
| 6์ฐจ์‹œ | 2023.10.17 | ํƒ์ƒ‰ | [์ฟผ๋“œ์••์ถ• ํ›„ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) |
| 7์ฐจ์‹œ | 2023.10.19 | ํƒ์ƒ‰ | [๋ฌด์ธ๋„ ์—ฌํ–‰](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) |
| 8์ฐจ์‹œ | 2023.10.21 | ํƒ์ƒ‰ | [๊ฑฐ๋ฆฌ๋‘๊ธฐ ํ™•์ธํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) |
| 9์ฐจ์‹œ | 2023.10.23 | ๋งต | [์Šคํ‚ฌ ํŠธ๋ฆฌ](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) |
| 10์ฐจ์‹œ | 2023.10.25 | ๊ตฌํ˜„ | [์ˆ˜์‹ ์ตœ๋Œ€ํ™”](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) |
| 11์ฐจ์‹œ | 2023.10.27 | ๋ฆฌ์ŠคํŠธ | [์˜์–ด ๋๋ง์ž‡๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) |
| 12์ฐจ์‹œ | 2023.10.30 | ํ | [์ด์ค‘์šฐ์„ ์ˆœ์œ„ํ](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) |
| 13์ฐจ์‹œ | 2023.11.01 | DP | [๋“ฑ๊ตฃ๊ธธ](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) |
| 14์ฐจ์‹œ | 2023.11.03 | ๋งต | [์‹œ์†Œ ์ง๊ฟ](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) |
| 15์ฐจ์‹œ | 2023.11.05 | ์ˆ˜ํ•™ | [์˜ˆ์ƒ ๋Œ€์ง„ํ‘œ](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) |
| 16์ฐจ์‹œ | 2023.11.08 | ์ˆ˜ํ•™ | [์ˆซ์ž ๋ณ€ํ™˜ํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) |
| 17์ฐจ์‹œ | 2023.11.10 | ์Šคํƒ | [์ง์ง€์–ด ์ œ๊ฑฐํ•˜๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) |
| 18์ฐจ์‹œ | 2023.11.13 | ๊ตฌํ˜„ | [ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) |
| 19์ฐจ์‹œ | 2023.11.17 | ๊ตฌํ˜„ | [์‹คํŒจ์œจ](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) |
| 20์ฐจ์‹œ | 2023.11.20 | ๋ฌธ์ž์—ด | [์˜น์•Œ์ด (2)](https://school.programmers.co.kr/learn/courses/30/lessons/133499) | [#70](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/70) |
| 21์ฐจ์‹œ | 2023.11.23 | ๋งต | [์˜์ƒ](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | [#73](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/73) |
| 22์ฐจ์‹œ | 2023.11.26 | ๊ทธ๋ฆฌ๋”” | [๊ตฌ๋ช…๋ณดํŠธ](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#79](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/79) |
Expand All @@ -37,4 +37,5 @@
| 33์ฐจ์‹œ | 2024.02.06 | ํ | [์ฒ ๋กœ](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/132) |
| 34์ฐจ์‹œ | 2024.02.12 | BFS | [์ด๋ถ„ ๊ทธ๋ž˜ํ”„](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35์ฐจ์‹œ | 2024.02.18 | ๊ทธ๋ฆฌ๋”” | [์„ ๋ฌผํ• ์ธ](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) |
| 36์ฐจ์‹œ | 2024.02.21 | ์ด์ง„ํƒ์ƒ‰ | [ํœด๊ฒŒ์†Œ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) |
| 36์ฐจ์‹œ | 2024.02.21 | ์ด์ง„ํƒ์ƒ‰ | [ํœด๊ฒŒ์†Œ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) |
| 37์ฐจ์‹œ | 2024.03.04 | ๊ตฌํ˜„ | [n+1 ์นด๋“œ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
53 changes: 53 additions & 0 deletions pknujsp/๊ตฌํ˜„/37-์นด๋“œ๊ฒŒ์ž„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
def solution(coin, cards):
a = set(cards[:len(cards) // 3])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ค€์„ฑ๋‹˜ ์ˆ˜๋„ ์ฝ”๋“œ๋ณด๋ฉด์„œ ์ฝ”๋“œ ์ž‘์„ฑํ•˜๋‹ค๊ฐ€ ๊ถ๊ธˆํ•œ๊ฒŒ ์ƒ๊ฒจ์„œ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊น๋‹ˆ๋‹น
set์ด ์•„๋‹ˆ๋ผ list๋กœ ๊ตฌํ˜„ํ•ด๋„ ํ†ต๊ณผ๋Š” ๋˜๋˜๋ฐ ์ง‘ํ•ฉ์œผ๋กœ ๊ตฌํ˜„ํ•˜์‹  ์ด์œ ๊ฐ€ ์‹œ๊ฐ„ ๋ณต์žก๋„ ๋•Œ๋ฌธ์ผ๊นŒ์š”?

for ~ in์—์„œ list์˜ ๊ฒฝ์šฐ์—๋Š” ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ O(n), set์˜ ๊ฒฝ์šฐ์—๋Š” O(1)์ด์—ฌ์„œ ์ง‘ํ•ฉ์œผ๋กœ ๊ตฌํ˜„ํ•˜์‹ ๊ฑด์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ค๋„ค ๋ง์”€ํ•˜์‹  ๊ทธ๋Œ€๋กœ ์ž…๋‹ˆ๋‹ค

์นด๋“œ ๋ชฉ๋ก์—์„œ n + 1 ์ด ๋˜๋Š” ์กฐํ•ฉ์„ ํ™•์ธํ•ด๋ณผ๋•Œ

๋ฆฌ์ŠคํŠธ๋กœ ํ•œ๋‹ค๋ฉด ๋ชจ๋“  ์นด๋“œ๋ฅผ ๋‘ ์Œ์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์ผ์ผํžˆ ๋‹ค ๋น„๊ตํ•ด์•ผ ํ•˜๋Š”๋ฐ

์ง‘ํ•ฉ์ด๋ผ๋ฉด ์Œ์œผ๋กœ ๋น„๊ตํ•  ํ•„์š”์—†์ด ์นด๋“œ ํ•˜๋‚˜์”ฉ๋งŒ ํ™•์ธํ•ด๋ณด๋ฉด์„œ n + 1 ์ด ๊ฐ€๋Šฅํ•œ ์นด๋“œ์˜ ์กด์žฌ์—ฌ๋ถ€๋ฅผ ํ•œ๋ฒˆ์— ํ™•์ธ๊ฐ€๋Šฅํ•˜๋‹ˆ๊นŒ์š”.

b = set()
t = len(cards) + 1
r = 1

for i in range(len(cards) // 3 + 1, len(cards), 2):
c1, c2 = cards[i - 1], cards[i]
b.add(c1)
b.add(c2)

removed = False
# ํ˜„์žฌ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์นด๋“œ ๋ชฉ๋ก ์ค‘ n + 1์ด ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ํ™•์ธ
for x in list(a):
if t - x in a:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t - x๋ฅผ ๋”ฐ๋กœ ๋ณ€์ˆ˜๋กœ ๋‹ด์„ ํ•„์š” ์—†์ด ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•˜๊ตฐ์š” .. ์ด๋ ‡๊ฒŒ ๋ณ€์ˆ˜ ํ•˜๋‚˜๋ฅผ ๋˜ ์ค„์ผ ์ˆ˜ ์žˆ๊ตฐ์š”.. ๐Ÿ‘

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต ์œ— ์ฝ”๋ฉ˜ํŠธ์˜ ๋‚ด์šฉ๊ณผ ๊ฐ™์€ ๋ถ€๋ถ„์œผ๋กœ ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค

a.remove(t - x)
a.remove(x)
removed = True
break

if removed:
r += 1
continue

# ์ฝ”์ธ์œผ๋กœ ๊ตํ™˜ํ•ด์„œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์นด๋“œ ์ค‘์—์„œ n + 1์ด ๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฐพ์•„์•ผ ํ•จ
# ์ฝ”์ธ์ด ์—†์œผ๋ฏ€๋กœ ์ข…๋ฃŒ
if not coin:
break

# `ํ˜„์žฌ ๊ฐ–๊ณ  ์žˆ๋Š” ์นด๋“œ + ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์นด๋“œ` = n + 1์ด ๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ํ™•์ธ
for x in list(b):
if t - x in a:
a.remove(t - x)
b.remove(x)
removed = True
coin -= 1
break
# ๋งˆ์ง€๋ง‰ ๋ฐฉ๋ฒ•์œผ๋กœ, ์˜ค์ง ๊ตํ™˜์œผ๋กœ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์นด๋“œ ๋ชฉ๋ก ์ค‘์—์„œ n + 1์ด ๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ํ™•์ธ
if not removed and coin >= 2:
for x in list(b):
if t - x in b:
b.remove(t - x)
b.remove(x)
removed = True
coin -= 2
break

# n + 1์„ ์–ด๋–ค ๊ฒฝ์šฐ์—๋„ ๋ชป ๋งŒ๋“ค๋ฉด ์ข…๋ฃŒ
if not removed:
break
r += 1

return r