-
Notifications
You must be signed in to change notification settings - Fork 5
Minjeong / 1월 2주차 / 5문제 #119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9178846
[PGS] 단어퍼즐 / Level 4 / 90분 / 실패 / 스킬체크 문제
Mingguriguri 247fd47
[PGS] 올바른 괄호의 갯수 / Level 4 / 60분 / 실패 / 스킬체크
Mingguriguri 8745f76
[BOJ] #1872. 스택 수열 / 실버2 / 40분 / 힌트,성공
Mingguriguri 46d7622
[BOJ] #17413. 단어 뒤집기 2 / 실버3 / 45분 / 성공
Mingguriguri 7ca4ff8
[BOJ] #16953. A->B / 실버2 / 40분 / 힌트,성공
Mingguriguri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| def solution(strs, t): | ||
| n = len(t) | ||
| dp = [1e9] * (n + 1) # 1e9는 불가능한 경우를 의미 | ||
| dp[0] = 0 # 초기값 설정: 시작점은 0 | ||
|
|
||
| # strs를 set으로 변환해 빠르게 포함 여부 확인 | ||
| str_set = set(strs) | ||
|
|
||
| # DP 진행 | ||
| for i in range(1, n + 1): | ||
| # 최대 5글자까지 확인 | ||
| for j in range(1, 6): | ||
| if i - j >= 0 and t[i - j:i] in str_set: | ||
| # 현재 위치를 j 길이만큼 뒤로 가서 비교 | ||
| dp[i] = min(dp[i], dp[i - j] + 1) | ||
|
|
||
| # 결과 반환: 완성 가능하면 dp[n], 불가능하면 -1 | ||
| return dp[n] if dp[n] != 1e9 else -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| def solution(n): | ||
| # DP 테이블 초기화 | ||
| dp = [0] * (n + 1) | ||
| dp[0] = 1 # 초기값 설정 (괄호가 없는 경우) | ||
|
|
||
| # 카탈란 수 점화식 적용 | ||
| for i in range(1, n + 1): | ||
| for j in range(i): | ||
| dp[i] += dp[j] * dp[i - j - 1] | ||
|
|
||
| return dp[n] # n개의 괄호쌍으로 만들 수 있는 경우의 수 반환 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import sys | ||
| from collections import deque | ||
| input = sys.stdin.readline | ||
|
|
||
| # 입력 받기 | ||
| A, B = map(int, input().split()) | ||
|
|
||
| # 큐 초기화 | ||
| queue = deque([A]) | ||
| cnt = 1 # 연산 횟수 | ||
|
|
||
| while queue: | ||
| # 현재 큐에서 모든 값을 탐색 | ||
| for _ in range(len(queue)): | ||
| current = queue.popleft() | ||
|
|
||
| # 현재 값이 B와 같으면 결과 출력 후 종료 | ||
| if current == B: | ||
| print(cnt) | ||
| exit() | ||
|
|
||
| # 다음 값을 큐에 추가 (B를 초과하지 않는 경우만) | ||
| if current * 2 <= B: | ||
| queue.append(current * 2) | ||
| if int(str(current)+"1") <= B: | ||
| queue.append(int(str(current)+"1")) | ||
|
|
||
| # 연산 횟수 증가 | ||
| cnt += 1 | ||
|
|
||
| # 큐가 비었다면 -1 출력 | ||
| print(-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import sys | ||
| from collections import deque | ||
|
|
||
| input = sys.stdin.readline | ||
|
|
||
| # 입력 문자열 처리 | ||
| S = deque(input().strip()) | ||
| temp = deque([]) # 단어를 저장하는 임시 리스트 | ||
| answer = deque([]) # 결과 저장 리스트 | ||
|
|
||
| tag = False # 태그 상태 확인 | ||
|
|
||
| while S: | ||
| # 태그 시작 | ||
| if S[0] == "<": | ||
| tag = True | ||
|
|
||
| # 태그 시작 또는 공백 처리 | ||
| if S[0] == " " or S[0] == "<": | ||
| # temp에 저장된 단어 뒤집기 | ||
| while temp: | ||
| answer.append(temp.pop()) | ||
| # 태그 내용 추가 | ||
| if tag: | ||
| while S[0] != ">": | ||
| answer.append(S.popleft()) | ||
| tag = False | ||
| # 공백 또는 닫는 태그 추가 | ||
| answer.append(S.popleft()) | ||
| else: | ||
| # 단어를 temp에 저장 | ||
| temp.append(S.popleft()) | ||
|
|
||
| # 남아 있는 단어 처리 | ||
| while temp: | ||
| answer.append(temp.pop()) | ||
|
|
||
| # 결과 출력 | ||
| print(''.join(answer)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import sys | ||
| from collections import deque | ||
|
|
||
| input = sys.stdin.readline | ||
|
|
||
| n = int(input()) # 수열의 길이 | ||
| stack = deque([]) # 스택 초기화 | ||
| answer = deque([]) # 연산 기록 | ||
| flag = True # 수열을 만들 수 있는지 확인하는 플래그 | ||
| current = 1 # 현재 push할 숫자 | ||
|
|
||
| # n번 반복하며 수열 입력 | ||
| for _ in range(n): | ||
| num = int(input()) | ||
|
|
||
| # 현재 숫자가 수열의 값에 도달할 때까지 push | ||
| while current <= num: | ||
| stack.append(current) | ||
| answer.append("+") | ||
| current += 1 | ||
|
|
||
| # 스택 최상단이 수열의 값과 일치하면 pop | ||
| if stack[-1] == num: | ||
| stack.pop() | ||
| answer.append("-") | ||
| else: | ||
| # 만들 수 없는 경우 | ||
| flag = False | ||
|
|
||
| # 결과 출력 | ||
| if flag: | ||
| for a in answer: | ||
| print(a) | ||
| else: | ||
| print("NO") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.