-
Notifications
You must be signed in to change notification settings - Fork 5
YoonYn9915 / 4월 2주차 / 3문제 #189
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
3 commits
Select commit
Hold shift + click to select a range
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,19 @@ | ||
|
|
||
| N = int(input()) | ||
|
|
||
| dp = [[0] * 10 for _ in range(N + 1)] | ||
|
|
||
| for i in range(1, 10): | ||
| dp[1][i] = 1 | ||
|
|
||
| for i in range(2, N + 1): | ||
| for j in range(10): | ||
| if j == 0: | ||
| dp[i][j] = dp[i - 1][1] | ||
| elif 1 <= j <= 8: | ||
| dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] | ||
| else: | ||
| dp[i][j] = dp[i - 1][8] | ||
|
|
||
|
|
||
| print(sum(dp[N]) % 1000000000) |
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,26 @@ | ||
| import sys | ||
|
|
||
| input = sys.stdin.readline | ||
|
|
||
| N = int(input()) | ||
| dp = [[[0 for _ in range(1 << 10)] for _ in range(10)] for _ in range(N)] | ||
| mod = 1000000000 | ||
| res = 0 | ||
|
|
||
| for k in range(1, 10): | ||
| dp[0][k][1 << k] = 1 | ||
|
|
||
| for i in range(1, N): | ||
| for k in range(10): | ||
| for bit in range(1024): | ||
| if k - 1 >= 0: | ||
| dp[i][k][bit | (1 << k)] += dp[i - 1][k - 1][bit] | ||
| if k + 1 <= 9: | ||
| dp[i][k][bit | (1 << k)] += dp[i - 1][k + 1][bit] | ||
| dp[i][k][bit | (1 << k)] %= mod | ||
|
|
||
| for k in range(10): | ||
| res += dp[N - 1][k][1023] | ||
| res %= mod | ||
|
|
||
| print(res) | ||
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,45 @@ | ||
|
|
||
| import sys | ||
|
|
||
| def recursion(paper, row_start, col_start, step): | ||
| # 종이가 같은지 검사 | ||
| result = check_paper_same(paper, row_start, col_start, step) | ||
|
|
||
| # 같지 않다면 9분할한뒤 각각을 재귀적으로 검사 | ||
| if result == 2: | ||
| for i in range(3): | ||
| for j in range(3): | ||
| row = row_start + (i * step // 3) | ||
| col = col_start + (j * step // 3) | ||
| recursion(paper, row, col, step // 3) | ||
| else: | ||
| # 종이의 칸이 다 같은 경우 | ||
| answer[result] += 1 | ||
|
|
||
|
|
||
|
|
||
| def check_paper_same(paper, row_start, col_start, step): | ||
| base = paper[row_start][col_start] | ||
| for i in range(row_start, row_start + step): | ||
| for j in range(col_start, col_start + step): | ||
| if paper[i][j] != base: | ||
| return 2 | ||
| return base | ||
|
|
||
|
|
||
| inp = sys.stdin.readline | ||
|
|
||
| n = int(inp()) | ||
|
|
||
| paper = [] | ||
|
|
||
| # 각각 -1, 0, 1로만 이루어진 종이의 개수 저장 튜플 | ||
| global answer | ||
| answer = {-1: 0, 0: 0, 1: 0} | ||
|
|
||
| for i in range(n): | ||
| paper.append(list(map(int, inp().split()))) | ||
|
|
||
| recursion(paper, 0, 0, n) | ||
|
|
||
| print('\n'.join(str(value) for value in answer.values())) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분이 제 코드랑 다른 부분인 것 같네요!! else 부분 없이 조건을 이렇게 둬도 된다는 점을 배워갑니다!