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

[이지민] - 겹치는 건 싫어, 기타리스트, 회전초밥, 쉬운 최단거리 #166

Merged
merged 4 commits into from
Sep 3, 2023
Merged
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
24 changes: 24 additions & 0 deletions src/main/kotlin/jimin/43week/겹치는 건 싫어.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
문제를 잘 못 이해했다.
https://khu98.tistory.com/187 보고 깨달았다.
'''

n, k = map(int, input().split())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n, k = 으로 받는 거 코틀린만 되는 줄 알았는데...

nums = list(map(int, input().split()))
nums_info = [0 for _ in range(max(nums) + 1)]
start = 0
end = 0
maxi = 0

while start < n and end < n:
if nums_info[nums[start]] < k:
nums_info[nums[start]] += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파이썬은 ++이 안되는게 흠이네요ㅜㅜ

start += 1
elif nums_info[nums[start]] == k:
nums_info[nums[end]] -= 1
maxi = max(maxi, start - end)
end += 1


maxi = max(maxi, n - end)
print(maxi)
27 changes: 27 additions & 0 deletions src/main/kotlin/jimin/43week/기타리스트.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'''
재귀로 했더니 시간초과가 났다.
재귀의 경우 2^(n + 1) - 2의 시간이 걸린다.
하지만 dp 테이블을 만들경우 n * m 으로 50,000만 걸린다!
Comment on lines +3 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간복잡도 설명 👍👍

https://jshong1125.tistory.com/56
'''


n, s, m = map(int, input().split())
v = list(map(int, input().split()))
dp = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
dp[0][s] = 1
for i in range(0, n):
for j in range(m + 1):
if dp[i][j] == 1:
plus = j + v[i]
minus = j - v[i]
if 0 <= plus <= m:
dp[i + 1][plus] = 1
if 0 <= minus <= m:
dp[i + 1][minus] = 1

maxi = -1
for i in range(m + 1):
if dp[-1][i] == 1:
maxi = i
print(maxi)
39 changes: 39 additions & 0 deletions src/main/kotlin/jimin/43week/쉬운 최단거리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from collections import deque


def bfs(x, y):
global n, m
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

queue = deque([])
result[x][y] = 0
queue.append([x, y])

while queue:
nx, ny = queue.popleft()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 그냥 큐는 없나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

있어요! 근데 보통 deque 쓰는 것 같더라고요

for i in range(4):
if 0 <= nx + dx[i] < n and 0 <= ny + dy[i] < m:
if ground[nx + dx[i]][ny + dy[i]] == 1 and result[nx + dx[i]][ny + dy[i]] == -1:
result[nx + dx[i]][ny + dy[i]] = result[nx][ny] + 1
queue.append([nx + dx[i], ny + dy[i]])
Comment on lines +15 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉..이부분 디게 깔끔하네요👍👍 한 수 배우고 갑니다..



n, m = map(int, input().split())
ground = []
result = [[-1 for _ in range(m)] for _ in range(n)]
x = 0
y = 0
for i in range(n):
g = list(map(int, input().split()))
for j in range(m):
if g[j] == 0:
result[i][j] = 0
elif g[j] == 2:
x = i
y = j
ground.append(g)

bfs(x, y)
for i in range(n):
print(" ".join(map(str, result[i])))
18 changes: 18 additions & 0 deletions src/main/kotlin/jimin/43week/회전초밥.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''
sushi[:3000] 까지만 더 해야 시간초과 안남!
'''

n, d, k, c = map(int, input().split())
sushi = []
for i in range(n):
sushi.append(int(input()))

maxi = 0
sushi += sushi[:3000]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉..아까 설명해주셨던 거 같은데 혹시 원래 sushi가 3000보다 작은 크기였다면 어떻게 되나요..?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 궁금쓰!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어 그러게요?ㅋㅋㅋㅋㅋ
근데 python은 크기가 커도 안터지는 것 같아요

for i in range(n):
eaten_sushi = sushi[i : i + k]
eaten_sushi.append(c)
eaten_sushi_length = len(list(set(eaten_sushi)))
maxi = max(maxi, eaten_sushi_length)

print(maxi)