-
Notifications
You must be signed in to change notification settings - Fork 0
[Aiden] - class4-2 #46
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
HanMulBit
wants to merge
7
commits into
main
Choose a base branch
from
aiden
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
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,21 @@ | ||
| import sys | ||
| data = sys.stdin.read().split() | ||
|
|
||
| n, m = int(data[0]), int(data[1]) | ||
| arr = [] | ||
| index = 2 | ||
| for _ in range(n): | ||
| arr.append(list(map(int, data[index:index + n]))) | ||
| index += n | ||
|
|
||
| dp = [[0] * (n + 1) for _ in range(n + 1)] | ||
|
|
||
| for i in range(1, n + 1): | ||
| for j in range(1, n + 1): | ||
| dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + arr[i-1][j-1] | ||
|
|
||
| for _ in range(m): | ||
| x1, y1, x2, y2 = map(int, data[index:index+4]) | ||
| result = dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1] | ||
| print(result) | ||
| index += 4 | ||
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,48 @@ | ||
| # 문제 | ||
| # 이 문제는 아주 평범한 배낭에 관한 문제이다. | ||
| # | ||
| # 한 달 후면 국가의 부름을 받게 되는 준서는 여행을 가려고 한다. | ||
| # 세상과의 단절을 슬퍼하며 최대한 즐기기 위한 여행이기 때문에, | ||
| # 가지고 다닐 배낭 또한 최대한 가치 있게 싸려고 한다. | ||
| # | ||
| # 준서가 여행에 필요하다고 생각하는 N개의 물건이 있다. | ||
| # 각 물건은 무게 W와 가치 V를 가지는데, 해당 물건을 배낭에 넣어서 가면 준서가 V만큼 즐길 수 있다. | ||
| # 아직 행군을 해본 적이 없는 준서는 최대 K만큼의 무게만을 넣을 수 있는 배낭만 들고 다닐 수 있다. | ||
| # 준서가 최대한 즐거운 여행을 하기 위해 배낭에 넣을 수 있는 물건들의 가치의 최댓값을 알려주자. | ||
|
|
||
| # 입력 | ||
| # 첫 줄에 물품의 수 N(1 ≤ N ≤ 100)과 준서가 버틸 수 있는 무게 K(1 ≤ K ≤ 100,000)가 주어진다. | ||
| # 두 번째 줄부터 N개의 줄에 거쳐 각 물건의 무게 W(1 ≤ W ≤ 100,000)와 | ||
| # 해당 물건의 가치 V(0 ≤ V ≤ 1,000)가 주어진다. | ||
| # | ||
| # 입력으로 주어지는 모든 수는 정수이다. | ||
| # | ||
| # 출력 | ||
| # 한 줄에 배낭에 넣을 수 있는 물건들의 가치합의 최댓값을 출력한다. | ||
| import sys | ||
|
|
||
| data = sys.stdin.read().split() | ||
|
|
||
| n = int(data[0]) | ||
| k = int(data[1]) | ||
| index = 2 | ||
| cargo = [] | ||
|
|
||
| for i in range(n): | ||
| w = int(data[index]) | ||
| v = int(data[index + 1]) | ||
| cargo.append((w, v)) | ||
| index += 2 | ||
|
|
||
| dp = [[0] * (k + 1) for _ in range(n + 1)] | ||
|
|
||
| for i in range(1, n + 1): | ||
| weight = cargo[i-1][0] | ||
| value = cargo[i-1][1] | ||
| for j in range(1, k + 1): | ||
| if j < weight: | ||
| dp[i][j] = dp[i-1][j] | ||
| else: | ||
| dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight] + value) | ||
|
|
||
| print(dp[n][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,52 @@ | ||
| # 문제 | ||
| # 수빈이는 동생과 숨바꼭질을 하고 있다. 수빈이는 현재 점 N(0 ≤ N ≤ 100,000)에 있고, | ||
| # 동생은 점 K(0 ≤ K ≤ 100,000)에 있다. 수빈이는 걷거나 순간이동을 할 수 있다. | ||
| # 만약, 수빈이의 위치가 X일 때 걷는다면 1초 후에 X-1 또는 X+1로 이동하게 된다. | ||
| # 순간이동을 하는 경우에는 0초 후에 2*X의 위치로 이동하게 된다. | ||
| # | ||
| # 수빈이와 동생의 위치가 주어졌을 때, | ||
| # 수빈이가 동생을 찾을 수 있는 가장 빠른 시간이 몇 초 후인지 구하는 프로그램을 작성하시오. | ||
| # | ||
| # 입력 | ||
| # 첫 번째 줄에 수빈이가 있는 위치 N과 동생이 있는 위치 K가 주어진다. N과 K는 정수이다. | ||
| # | ||
| # 출력 | ||
| # 수빈이가 동생을 찾는 가장 빠른 시간을 출력한다. | ||
| from collections import deque | ||
|
|
||
| def walk(x): | ||
| return [x-1,x+1] | ||
|
|
||
| def tel(x): | ||
| return x * 2 | ||
|
|
||
| def bfs(n,k): | ||
| max_limit = 100001 | ||
| visit = [False] * max_limit | ||
| distance = [0] * max_limit | ||
|
|
||
| queue = deque([n]) | ||
| visit[n] = True | ||
|
|
||
| while queue: | ||
| current = queue.popleft() | ||
|
|
||
| if current == k: | ||
| return distance[current] | ||
|
|
||
| # 순간이동 처리 (0초 걸림) | ||
| next_pos = tel(current) | ||
| if 0 <= next_pos < max_limit and not visit[next_pos]: | ||
| visit[next_pos] = True | ||
| distance[next_pos] = distance[current] | ||
| queue.appendleft(next_pos) # 순간이동은 우선순위를 높이기 위해 앞에 추가 | ||
|
|
||
| # 걷기 처리 (1초 걸림) | ||
| for next_pos in walk(current): | ||
| if 0 <= next_pos < max_limit and not visit[next_pos]: | ||
| visit[next_pos] = True | ||
| distance[next_pos] = distance[current] + 1 | ||
| queue.append(next_pos) | ||
|
|
||
| n, k = map(int, input().split()) | ||
| print(bfs(n, 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,43 @@ | ||
| import sys | ||
| import heapq | ||
|
|
||
| data = sys.stdin.read().split() | ||
| inf = int(1e9) | ||
|
|
||
| V = int(data[0]) | ||
| E = int(data[1]) | ||
| K = int(data[2]) | ||
|
|
||
| graph = [[] for _ in range(V + 1)] | ||
| distance = [inf] * (V + 1) | ||
|
|
||
| index = 3 | ||
|
|
||
| for _ in range(E): | ||
| u = int(data[index]) | ||
| v = int(data[index + 1]) | ||
| w = int(data[index + 2]) | ||
| graph[u].append((v, w)) | ||
| index += 3 | ||
|
|
||
| def short_distance(start): | ||
| q = [] | ||
| heapq.heappush(q, (0, start)) | ||
| distance[start] = 0 | ||
| while q: | ||
| dist, now = heapq.heappop(q) | ||
| if distance[now] < dist: | ||
| continue | ||
| for i in graph[now]: | ||
| cost = dist + i[1] | ||
| if cost < distance[i[0]]: | ||
| distance[i[0]] = cost | ||
| heapq.heappush(q, (cost, i[0])) | ||
|
|
||
| short_distance(K) | ||
|
|
||
| for i in range(1, V + 1): | ||
| if distance[i] == inf: | ||
| print("INF") | ||
| else: | ||
| print(distance[i]) |
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,42 @@ | ||
| import sys | ||
| from collections import deque, defaultdict | ||
|
|
||
| data = sys.stdin.read().split() | ||
|
|
||
| n = int(data[0]) | ||
| index = 1 | ||
| graph = defaultdict(list) | ||
|
|
||
| for _ in range(n-1): | ||
| u, v, w = map(int, data[index:index+3]) | ||
| graph[u].append((v, w)) | ||
| graph[v].append((u, w)) | ||
| index += 3 | ||
|
|
||
| def bfs(start): | ||
| distance = [-1] * (n + 1) | ||
| distance[start] = 0 | ||
| q = deque([start]) | ||
|
|
||
| max_dist = 0 | ||
| farthest_node = start | ||
|
|
||
| while q: | ||
| node = q.popleft() | ||
|
|
||
| for neighbor, weight in graph[node]: | ||
| if distance[neighbor] == -1: | ||
| distance[neighbor] = distance[node] + weight | ||
| q.append(neighbor) | ||
|
|
||
| if distance[neighbor] > max_dist: | ||
| max_dist = distance[neighbor] | ||
| farthest_node = neighbor | ||
|
|
||
| return farthest_node, max_dist | ||
|
|
||
| farthest_node, _ = bfs(1) | ||
|
|
||
| _, tree_diameter = bfs(farthest_node) | ||
|
|
||
| print(tree_diameter) |
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 lcs(s1, s2): | ||
|
|
||
| dp = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)] | ||
|
|
||
| for i in range(1, len(s1) + 1): | ||
| for j in range(1, len(s2) + 1): | ||
| if s1[i-1] == s2[j-1]: | ||
| dp[i][j] = dp[i-1][j-1] + 1 | ||
|
|
||
| else: | ||
| dp[i][j] = max(dp[i-1][j], dp[i][j-1]) | ||
|
|
||
| return dp[len(s1)][len(s2)] | ||
|
|
||
| s1 = input().strip() | ||
| s2 = input().strip() | ||
|
|
||
| print(lcs(s1,s2)) |
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,25 @@ | ||
| def safe(row, col): | ||
| for i in range(row): | ||
| if col == queens[i] or abs(col - queens[i]) == row - i: | ||
| return False | ||
| return True | ||
|
|
||
| def near_queens(row): | ||
| global count # 전역 변수 count를 사용하겠다는 선언 | ||
| # 사용 시 def 함수 외에서 선언된 변수를 내부에서 사용 가능 | ||
| if row == n: | ||
| count += 1 | ||
| return | ||
| for col in range(n): | ||
| if not col_used[col] and not diag1_used[row + col] and not diag2_used[row - col + n - 1]: | ||
| col_used[col] = diag1_used[row + col] = diag2_used[row - col + n - 1] = True | ||
| near_queens(row + 1) | ||
| col_used[col] = diag1_used[row + col] = diag2_used[row - col + n - 1] = False | ||
|
|
||
| n = int(input()) | ||
| col_used = [False] * n | ||
| diag1_used = [False] * (2 * n - 1) | ||
| diag2_used = [False] * (2 * n - 1) | ||
| count = 0 | ||
| near_queens(0) | ||
| print(count) |
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.