Skip to content

Commit

Permalink
Merge branch 'main' into 4-H0ngJu
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu authored Mar 25, 2024
2 parents f77be4e + 301cbcc commit 865b02b
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 23 deletions.
2 changes: 2 additions & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.05 | ํ | [ํ”„๋กœ์„ธ์Šค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
| 2์ฐจ์‹œ | 2024.03.07 | ํ | [๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๋Š” ํŠธ๋Ÿญ](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 |
| 3์ฐจ์‹œ | 2024.03.10 | ํž™ | [N๋ฒˆ์งธ ํฐ ์ˆ˜](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 |
| 4์ฐจ์‹œ | 2024.03.13 | ํž™ | [๋ฌธ์ œ์ง‘](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from collections import deque

def solution(bridge_length, weight, truck_weights):
time = 0
onBridge = deque() # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ
truckNum = 0 # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ ์ˆ˜
sum = 0 # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ ๋ฌด๊ฒŒ์˜ ํ•ฉ
truck_weights = deque(truck_weights)

while truck_weights or onBridge:
time += 1

# ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๊ฐ€๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
if onBridge and time - onBridge[0][1] >= bridge_length:
sum -= onBridge.popleft()[0]
truckNum -= 1

# ๋‹ค์Œ ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ์— ์˜ฌ๋ผ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
# ํŠธ๋Ÿญ์ด ์žˆ๊ณ  ํ•ฉ์ด weight์„ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ์ˆ˜๊ฐ€ bridge_length๋ฅผ ๋„˜๊ธฐ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ
if len(truck_weights) != 0 and sum + truck_weights[0] <= weight and truckNum + 1 <= bridge_length:
truck = truck_weights.popleft() # pop
onBridge.append((truck, time)) # ๋‹ค๋ฆฌ ์œ„์˜ truck์— tuple ์ถ”๊ฐ€
sum += truck # ๋ฌด๊ฒŒ ์ถ”๊ฐ€
truckNum += 1 # ๊ฑด๋„ˆ๊ณ  ์žˆ๋Š” ํŠธ๋Ÿญ ์ถ”๊ฐ€

return time
19 changes: 19 additions & 0 deletions H0ngJu/ํž™/N๋ฒˆ์งธ ํฐ ์ˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import heapq

line = int(sys.stdin.readline().strip())

heap = []
heapq.heapify(heap)

for i in range(line):
data = list(map(int, sys.stdin.readline().strip().split()))
for s in data:
if len(heap) < line:
heapq.heappush(heap, s)
else:
if s > heap[0]:
heapq.heappop(heap)
heapq.heappush(heap, s)

print(heap[0])
1 change: 1 addition & 0 deletions Munbin-Lee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@
| 35์ฐจ์‹œ | 2024.02.18 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/24891">๋‹จ์–ด ๋งˆ๋ฐฉ์ง„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/140 |
| 36์ฐจ์‹œ | 2024.02.21 | ๋ฌธ์ž์—ด | <a href="https://www.acmicpc.net/problem/15927">ํšŒ๋ฌธ์€ ํšŒ๋ฌธ์•„๋‹ˆ์•ผ!!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143 |
| 37์ฐจ์‹œ | 2024.03.05 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/250136">์„์œ  ์‹œ์ถ”</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/150 |
| 37์ฐจ์‹œ | 2024.03.08 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/5052">์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/155 |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <iostream>
#include <vector>

using namespace std;

struct Trie {
struct Node {
Node *children[10]{};
bool isTerminal = false;
};

Node *root = new Node;

bool insert(string &s) const {
auto cur = root;

for (char ch: s) {
int digit = ch - '0';

if (!cur->children[digit]) {
cur->children[digit] = new Node();
cur = cur->children[digit];
continue;
}

if (cur->children[digit]->isTerminal) {
return false;
}

cur = cur->children[digit];
}

for (auto child: cur->children) {
if (child) {
return false;
}
}

cur->isTerminal = true;

return true;
}
};

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);

auto solve = []() {
auto trie = new Trie;

int n;
cin >> n;

vector<string> numbers(n);

for (auto &number: numbers) {
cin >> number;
}

for (auto number: numbers) {
if (!trie->insert(number)) {
cout << "NO\n";
delete trie;
return;
}
}

cout << "YES\n";
};

int t;
cin >> t;

while (t--) {
solve();
}

return 0;
}
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])
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:
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
78 changes: 78 additions & 0 deletions tgyuuAn/DFS/์Šค๋„์ฟ .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import sys

def input(): return sys.stdin.readline().rstrip()

board = []

for _ in range(9): board.append(list(input()))

def dfs(board, now_row, now_col):

# ์ด๋ฏธ ๋“ค์–ด์žˆ๋Š” ์นธ์ผ ๊ฒฝ์šฐ
if board[now_row][now_col] != "0":
new_row = now_row
new_col = now_col + 1

if new_col >= 9:
new_col = 0
new_row += 1

# ์Šค๋„์ฟ  ์™„์„ฑ
if new_row >= 9: return board

temp = dfs(board, new_row, new_col)

if temp is not None: return temp

# ๋น„์–ด์žˆ๋Š” ์นธ์ผ ๊ฒฝ์šฐ
else:
need_number = { str(x) for x in range(1,10) }

# ๊ฐ€๋กœ ํ–‰ ๊ฒ€์‚ฌ
for col in range(9):
if board[now_row][col] != "0":
need_number.discard(board[now_row][col])

# ์„ธ๋กœ ํ–‰ ๊ฒ€์‚ฌ
for row in range(9):
if board[row][now_col] != "0":
need_number.discard(board[row][now_col])

# 3X3 ๊ฒ€์‚ฌ
temp_row = (now_row//3)*3
temp_col = (now_col//3)*3
for inner_row in range(temp_row, temp_row+3):
for inner_col in range(temp_col, temp_col+3):
if board[inner_row][inner_col] != "0":
need_number.discard(board[inner_row][inner_col])

# ๋งŒ์•ฝ ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š”๊ฒƒ์ด ์—†์œผ๋ฉด None์„ ๋ฆฌํ„ด
if len(need_number) == 0: return None

need_number = sorted(list(map(int,need_number)))

for dedicate_number in need_number:
board[now_row][now_col] = str(dedicate_number)

new_row = now_row
new_col = now_col + 1

if new_col >= 9:
new_col = 0
new_row += 1

# ์Šค๋„์ฟ  ์™„์„ฑ
if new_row >= 9: return board

temp = dfs(board, new_row, new_col)

if temp is not None: return temp

board[now_row][now_col] = "0"

return None

answer = dfs(board, 0, 0)

for row in answer:
print("".join(row))
Loading

0 comments on commit 865b02b

Please sign in to comment.