Skip to content

Commit

Permalink
2024-07-14 01:47:42
Browse files Browse the repository at this point in the history
Affected files:
.obsidian/workspace.json
src/content/blog/boj-2529-부등호.md
  • Loading branch information
gyunseo committed Jul 13, 2024
1 parent e4ad0ad commit 01e076d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"state": {
"type": "backlink",
"state": {
"file": "src/content/blog/boj-1339-단어-수학.md",
"file": "src/content/blog/boj-2529-부등호.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -120,7 +120,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "src/content/blog/boj-1339-단어-수학.md",
"file": "src/content/blog/boj-2529-부등호.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand All @@ -143,7 +143,7 @@
"state": {
"type": "outline",
"state": {
"file": "src/content/blog/boj-1339-단어-수학.md"
"file": "src/content/blog/boj-2529-부등호.md"
}
}
}
Expand All @@ -166,10 +166,10 @@
"table-editor-obsidian:Advanced Tables Toolbar": false
}
},
"active": "71e0df042bc7a561",
"active": "bb9e313e9ec35bc3",
"lastOpenFiles": [
"src/content/blog/boj-2529-부등호.md",
"src/content/blog/boj-1339-단어-수학.md",
"src/content/blog/boj-2529-부등호.md",
"src/content/blog/boj-2660-회장뽑기.md",
"src/content/blog/boj-2011-암호코드.md",
"src/content/blog/leet-code-438-find-all-anagrams-in-a-string.md",
Expand Down
50 changes: 49 additions & 1 deletion src/content/blog/boj-2529-부등호.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ogImage: ""
![](https://res.cloudinary.com/gyunseo-blog/image/upload/f_auto/v1720540092/image_fux9f7.png)

그런데, 아직 원인 파악은 못했습니다.
계속 시간 초과가 뜨네요...
계속 시간 초과가 뜨네요... (`eval`함수가 병목 구간이었습니다 ㅎㅎ)
그래서 아쉬운 대로 DFS + 백트래킹으로 구현했습니다!

## 구현
Expand Down Expand Up @@ -76,3 +76,51 @@ if __name__ == "__main__":
print(maxStr)
print(minStr)
```

```python
import sys
from itertools import permutations

input = sys.stdin.readline

def check(a, b, op):
if op == "<":
return a < b
else:
return a > b
if __name__ == "__main__":
K = int(input().strip())
operators = input().strip().split()

maxSeqSum = 0
minSeqSum = 9999999999
maxSeq, minSeq = None, None
seqCandsGen = permutations(range(10), K + 1)

for candSeq in seqCandsGen:
isValid = True
for i, operator in enumerate(operators):
if not check(candSeq[i], candSeq[i + 1], operator):
isValid = False
break

if isValid:
seqSum = 0
factor = 1
for idx in range(K, -1, -1):
seqSum += candSeq[idx] * factor
factor *= 10
# print(f"seqSum: {seqSum}")
if seqSum > maxSeqSum:
maxSeq = candSeq
maxSeqSum = seqSum
if seqSum < minSeqSum:
minSeq = candSeq
minSeqSum = seqSum
# print(f"minSeq: {minSeq}")

# print(maxSeq, minSeq)
print("".join(map(str, maxSeq)))
print("".join(map(str, minSeq)))

```

0 comments on commit 01e076d

Please sign in to comment.