Skip to content
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

6월 1주차 이정욱 #116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions 2023/06_June/week1/이정욱/1727_커플만들기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

n,m = map(int,input().split())
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))

if n > m:
l1, l2 = l2, l1
n,m = m,n

dp = [[0 for _ in range(m)] for _ in range(n)]

l1.sort()
l2.sort()

dp[0][0] = abs(l1[0] - l2[0])

for j in range(1,m-(n-1)):
dp[0][j] = min(abs(l1[0] - l2[j]), dp[0][j-1])

for i in range(1, n):
for j in range(i, m - (n - i - 1)):
if i == j:
dp[i][j] = dp[i - 1][j - 1] + abs(l1[i] - l2[j])
else:
dp[i][j] = min(dp[i - 1][j - 1] + abs(l1[i] - l2[j]), dp[i][j - 1])

print(dp[n-1][m-1])
19 changes: 19 additions & 0 deletions 2023/06_June/week1/이정욱/17425_약수의합.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

t = int(input())

fx = [0 for _ in range(1000000+1)]
gx = [0]

for i in range(1, 1000000+1):
for j in range(i, 1000000+1, i):
fx[j] += i

for e in fx:
gx.append(gx[-1]+e)

for _ in range(t):
n = int(input())
print(gx[n+1])
71 changes: 71 additions & 0 deletions 2023/06_June/week1/이정욱/17779_게리맨더링2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import sys
from copy import deepcopy
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

n = int(input())
arr = [list(map(int,input().split())) for _ in range(n)]

state = [0,0,1,1]

def cal():
x,y,d1,d2 = state
wards = [0,0,0,0,0,0]

a = y
b = y
cnt = 0

for i in range(n):
for j in range(n):
if i < x:
if j <= y:
wards[1] += arr[i][j]
else:
wards[2] += arr[i][j]
elif i > x+d1+d2:
if j <= y-d1+d2-1:
wards[3] += arr[i][j]
else:
wards[4] += arr[i][j]
else:
if a <= j <= b:
wards[5] += arr[i][j]
elif j < a:
if cnt < d1:
wards[1] += arr[i][j]
else:
wards[3] += arr[i][j]
else:
if cnt <= d2:
wards[2] += arr[i][j]
else:
wards[4] += arr[i][j]

if x <= i <= x+d1+d2:
if cnt < d1:
a -= 1
else:
a += 1
if cnt < d2:
b += 1
else:
b -= 1
cnt += 1
return wards

res = 1e10

for x in range(n):
for y in range(n):
for d1 in range(n):
for d2 in range(n):
state = [x,y,d1,d2]
wards = cal()
wards[0] = wards[1]
_,a1,a2,a3,a4,a5 = wards
if a1 == 0 or a2 == 0 or a3 == 0 or a4 == 0 or a5 == 0:
continue
res = min(res,abs(max(wards)-min(wards)))

print(res)
40 changes: 40 additions & 0 deletions 2023/06_June/week1/이정욱/21278_호석이두마리치킨.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys
from itertools import combinations
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
dist = [[1e10 for _ in range(n+1)] for _ in range(n+1)]

for _ in range(m):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
dist[a][b] = 1
dist[b][a] = 1


for k in range(1,n+1):
for i in range(1,n+1):
for j in range(1,n+1):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

res = [1e10,[]]

def get_dist(a,b):
if a == b: return 0
return dist[a][b]


for i in range(1,n+1):
for j in range(i+1,n+1):
_sum = 0
for k in range(1,n+1):
_sum += min(get_dist(i,k), get_dist(j,k))
if _sum == res[0]:
res[1].append((i,j))
elif _sum < res[0]:
res = [_sum, [(i,j)]]
res[1].sort()
print(f"{res[1][0][0]} {res[1][0][1]} {res[0]*2}")
34 changes: 34 additions & 0 deletions 2023/06_June/week1/이정욱/21758_꿀따기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

n = int(input())
arr = list(map(int,input().split()))

_sum = [0]

for e in arr:
_sum.append(_sum[-1] + e)

res = 0
# 112
bee1 = 0
hive = n-1

for bee2 in range(1,n-1):
res = max(res, (_sum[hive+1]-_sum[bee1+1]-arr[bee2]) + (_sum[hive+1]-_sum[bee2+1]))
# 211
hive = 0
bee2 = n-1

for bee1 in range(1,n-1):
res = max(res, (_sum[bee1]-_sum[hive]) + (_sum[bee2]-_sum[hive]-arr[bee1]))
# 121
bee1 = 0
bee2 = n-1

for hive in range(1,n-1):
res = max(res,(_sum[hive+1]-_sum[bee1+1]) + (_sum[bee2]-_sum[hive]))


print(res)
17 changes: 17 additions & 0 deletions 2023/06_June/week1/이정욱/22871_징검다리건너기(large).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

n = int(input())
arr = list(map(int,input().split()))

dp = [1e10 for _ in range(n+1)]

dp[0] = 0

for j in range(1,n):
for i in range(0,j):
k = max((j-i)*(1+abs(arr[i]-arr[j])),dp[i])
dp[j] = min(k,dp[j])

print(dp[n-1])