Skip to content

Commit

Permalink
22.08.22
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Aug 22, 2022
1 parent e4c91fe commit 079a09e
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 0 deletions.
15 changes: 15 additions & 0 deletions BAEKJOON/11403_경로_찾기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
def input(): return sys.stdin.readline().strip()


N = int(input())
data = [list(map(int, input().split())) for _ in range(N)]
dp = [data[i][:] for i in range(N)]

for i in range(N):
for j in range(N):
for k in range(N):
dp[j][k] = max(dp[j][k], dp[j][i] * dp[i][k])

for arr in dp:
print(*arr, sep=' ')
33 changes: 33 additions & 0 deletions BAEKJOON/14267_회사_문화_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from collections import deque
import sys
def input(): return sys.stdin.readline().strip()


N, M = map(int, input().split())
edges = [[] for _ in range(N + 1)]
for i, x in enumerate(list(map(int, input().split()))):
if x != -1:
edges[i + 1].append(x)
edges[x].append(i + 1)

nodes = [0] * (N + 1)
for _ in range(M):
i, w = map(int, input().split())
nodes[i] = nodes[i] + w

visited = [False] * (N + 1)
visited[1] = True

queue = deque([(1, 0)])
while queue:
here, cost = queue.popleft()
nodes[here] = nodes[here] + cost

for there in edges[here]:
if visited[there]:
continue

visited[there] = True
queue.append((there, nodes[here]))

print(*nodes[1:], sep=' ')
29 changes: 29 additions & 0 deletions BAEKJOON/1717_집합의_표현.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
def input(): return sys.stdin.readline().strip()


def get(idx):
here = idx
while here != union[here]:
here = union[here]
root = here

here = idx
while here != union[here]:
here, union[here] = union[here], root
return root


N, M = map(int, input().split())
union = [i for i in range(N + 1)]
for _ in range(M):
o, a, b = map(int, input().split())

if o == 0:
union[get(a)] = get(b)

if o == 1:
if get(a) == get(b):
print("YES")
else:
print("NO")
29 changes: 29 additions & 0 deletions BAEKJOON/1806_부분합.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
sys.stdin = open("1.txt")
def input(): return sys.stdin.readline().strip()


def max_sum(idx):
answer, psum = float('inf'), 0
for i, num in enumerate(data):
if i < idx:
psum = psum + num
if i == idx - 1:
answer = psum
continue
psum = psum + num - data[i - idx]
answer = max(answer, psum)
return answer


N, S = map(int, input().split())
data = list(map(int, input().split()))

s, e = 1, N + 1
while s < e:
m = (s + e) // 2
if max_sum(m) >= S:
e = m
else:
s = m + 1
print(e if e <= N else 0)
5 changes: 5 additions & 0 deletions BAEKJOON/1904_01타일.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
N = int(input())
dp = (1, 1)
for i in range(N):
dp = (dp[1] % 15746, (dp[0] + dp[1]) % 15746)
print(dp[0])
12 changes: 12 additions & 0 deletions BAEKJOON/1932_정수_삼각형.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
def input(): return sys.stdin.readline().strip()


N = int(input())
data = [list(map(int, input().split())) for _ in range(N)]
dp = [0] * (N + 1)

for i in range(N):
for j in range(i, -1, -1):
dp[j] = max(dp[j - 1], dp[j]) + data[i][j]
print(max(dp))
18 changes: 18 additions & 0 deletions BAEKJOON/9020_골드바흐의_추측.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
def input(): return sys.stdin.readline().strip()


is_prime = [True] * 10001
for i in range(2, 10001):
if not is_prime[i]:
continue
for j in range(2 * i, 10001, i):
is_prime[j] = False

T = int(input())
for _ in range(T):
N = int(input())
for i in range(N // 2, 1, -1):
if is_prime[i] and is_prime[N - i]:
print(i, N - i, sep=' ')
break
11 changes: 11 additions & 0 deletions BAEKJOON/9461_파도반_수열.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
def input(): return sys.stdin.readline().strip()


dp = [0, 1, 1, 1, 2, 2] + [0] * (95)
for i in range(6, 101):
dp[i] = dp[i - 1] + dp[i - 5]

T = int(input())
for _ in range(T):
print(dp[int(input())])

0 comments on commit 079a09e

Please sign in to comment.