-
Notifications
You must be signed in to change notification settings - Fork 0
[sean] - class4-2 #44
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
Open
timepresent95
wants to merge
7
commits into
main
Choose a base branch
from
sean-4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ace0bc9
#43 11660.py
timepresent95 0886d98
#43 9251.py
timepresent95 67b83d9
#43 12865.py
timepresent95 6e046b7
#43 13549.py
timepresent95 e18dbeb
#43 1753.py
timepresent95 77c4748
#43 1967.py
timepresent95 2bbe850
#43 9663.py
timepresent95 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,23 @@ | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| n, m = map(int, input().split()) | ||
|
|
||
| arr = [list(map(int, input().split())) for _ in range(n)] | ||
|
|
||
| sum_arr = [[0] * n for _ in range(n)] | ||
|
|
||
| for i in range(0, n): | ||
| for j in range(n): | ||
| prev_row = sum_arr[i - 1][j] if (i != 0) else 0 | ||
| prev_col = sum_arr[i][j - 1] if (j != 0) else 0 | ||
| prev_sum = sum_arr[i - 1][j - 1] if (i != 0 and j != 0) else 0 | ||
| sum_arr[i][j] = arr[i][j] + prev_row + prev_col - prev_sum | ||
|
|
||
| for _ in range(m): | ||
| x1, y1, x2, y2 = map(lambda x: int(x) - 1, input().split()) | ||
| prev_row = sum_arr[x1 - 1][y2] if (x1 != 0) else 0 | ||
| prev_col = sum_arr[x2][y1 - 1] if (y1 != 0) else 0 | ||
| prev_sum = sum_arr[x1 - 1][y1 - 1] if (x1 != 0 and y1 != 0) else 0 | ||
| print(sum_arr[x2][y2] - prev_row - prev_col + prev_sum) |
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,22 @@ | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| n, k = map(int, input().split()) | ||
|
|
||
| items = sorted( | ||
| [list(map(int, input().split())) for _ in range(n)], | ||
| key=lambda x: x[1] / x[0], | ||
| reverse=True, | ||
| ) | ||
|
|
||
| dp = [0] * (k + 1) | ||
|
|
||
| answer = 0 | ||
| for weight, price in items: | ||
| for i in range(k, weight - 1, -1): | ||
| if i - weight >= 0: | ||
| dp[i] = max(dp[i], dp[i - weight] + price) | ||
| answer = max(answer, dp[i]) | ||
|
|
||
| print(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,27 @@ | ||
| from collections import deque | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| n, k = map(int, input().split()) | ||
|
|
||
| MAX_POS = 200000 | ||
|
|
||
| dp = [MAX_POS + 1] * (MAX_POS + 1) | ||
|
|
||
| queue = deque([n]) | ||
| dp[n] = 0 | ||
|
|
||
| while queue: | ||
| x = queue.popleft() | ||
| if x != 0 and dp[x - 1] > dp[x] + 1: | ||
| dp[x - 1] = dp[x] + 1 | ||
| queue.append(x - 1) | ||
| if x + 1 <= MAX_POS and dp[x + 1] > dp[x] + 1: | ||
| dp[x + 1] = dp[x] + 1 | ||
| queue.append(x + 1) | ||
| if 2 * x <= MAX_POS and dp[2 * x] > dp[x]: | ||
| dp[2 * x] = dp[x] | ||
| queue.append(2 * x) | ||
|
|
||
| print(dp[k]) |
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,33 @@ | ||
| import heapq | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| v, e = map(int, input().split()) | ||
| k = int(input()) | ||
|
|
||
|
|
||
| graph = {i: [] for i in range(1, v + 1)} | ||
| for i in range(e): | ||
| _u, _v, _w = map(int, input().split()) | ||
| graph[_u].append((_v, _w)) | ||
|
|
||
| distance = [float("inf")] * (v + 1) | ||
| distance[k] = 0 | ||
|
|
||
| pq = [] | ||
| heapq.heappush(pq, (0, k)) | ||
|
|
||
| while pq: | ||
| _w, cur = heapq.heappop(pq) | ||
|
|
||
| if _w > distance[cur]: | ||
| continue | ||
|
|
||
| for next, weight in graph[cur]: | ||
| next_weight = _w + weight | ||
| if next_weight < distance[next]: | ||
| distance[next] = next_weight | ||
| heapq.heappush(pq, (next_weight, next)) | ||
|
|
||
| print("\n".join(map(lambda x: str(x) if x != float("inf") else "INF", distance[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,30 @@ | ||
| from collections import deque | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| n = int(input()) | ||
|
|
||
| tree = [[] for _ in range(n + 1)] | ||
|
|
||
| for _ in range(n - 1): | ||
| a, b, c = map(int, input().split()) | ||
| tree[a].append((b, c)) | ||
| tree[b].append((a, c)) | ||
|
|
||
| answer = 0 | ||
| for root in range(1, n + 1): | ||
| visited = [-1] * (n + 1) | ||
| visited[root] = 0 | ||
|
|
||
| queue = deque([root]) | ||
| while queue: | ||
| cur = queue.popleft() | ||
|
|
||
| for next, weight in tree[cur]: | ||
| if visited[next] == -1: | ||
| visited[next] = visited[cur] + weight | ||
| queue.append(next) | ||
| answer = max(answer, visited[next]) | ||
|
|
||
| print(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,22 @@ | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| sequence = [input(), input()] | ||
|
|
||
| sequence_table = [[0] * (len(sequence[1]) + 1) for _ in range(len(sequence[0]) + 1)] | ||
|
|
||
|
|
||
| answer = 0 | ||
| for i in range(1, len(sequence[0]) + 1): | ||
| for j in range(1, len(sequence[1]) + 1): | ||
| if sequence[0][i - 1] == sequence[1][j - 1]: | ||
| prev = sequence_table[i - 1][j - 1] if (i != 0 and j != 0) else 0 | ||
timepresent95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sequence_table[i][j] = prev + 1 | ||
| else: | ||
| prev_row = sequence_table[i - 1][j] if (i != 0) else 0 | ||
| prev_col = sequence_table[i][j - 1] if (j != 0) else 0 | ||
| sequence_table[i][j] = max(prev_row, prev_col) | ||
| answer = max(answer, sequence_table[i][j]) | ||
|
|
||
| print(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,26 @@ | ||
| import sys | ||
|
|
||
| # sys.stdin = open("input.txt", "r") | ||
|
|
||
| n = int(input()) | ||
|
|
||
|
|
||
| def n_queen(row, col, sum, diff): | ||
| if row == n: | ||
| return 1 | ||
|
|
||
| ret = 0 | ||
| for j in range(0, n): | ||
| if col[j] or sum[row + j] or diff[row - j + n]: | ||
| continue | ||
| col[j] = True | ||
| sum[row + j] = True | ||
| diff[row - j + n] = True | ||
| ret = ret + n_queen(row + 1, col, sum, diff) | ||
| col[j] = False | ||
| sum[row + j] = False | ||
| diff[row - j + n] = False | ||
| return ret | ||
|
|
||
|
|
||
| print(n_queen(0, [False] * n, [False] * (2 * n), [False] * (2 * n))) |
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.