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

41-pknujsp #169

Merged
merged 5 commits into from
May 3, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ์ž๋ฌผ์‡ ์˜ ์ค‘๊ฐ„ ๋ถ€๋ถ„์ด ๋ชจ๋‘ 1์ธ์ง€ ํ™•์ธ
def is_valid(new_lock):
length = len(new_lock) // 3

for r in range(length, length * 2):
for c in range(length, length * 2):
if new_lock[r][c] != 1:
return False

return True

def solution(key, lock):
n = len(lock)
k = len(key)
new_lock = [[0] * (n * 3) for _ in range(n * 3)]

for r in range(n):
for c in range(n):
new_lock[r + n][c + n] = lock[r][c]

for _ in range(4):
rev_key = key[::-1]
key = []
for c in range(k):
row = []
for r in range(k):
row.append(rev_key[r][c])
key.append(row)

"""
์—ด์‡ ๋ฅผ ๋Œ๋ฆฌ๋Š” ๋กœ์ง์€ ํ•œ ์ค„๋กœ๋„ ๊ตฌํ˜„๊ฐ€๋Šฅ ํ•ฉ๋‹ˆ๋‹ค
key = [row for row in zip(*reversed(key))]
"""

for r in range(n * 2):
for c in range(n * 2):
# ์ž๋ฌผ์‡ ์— ์—ด์‡ ๋ฅผ ๋ผ์šด๋‹ค
for i in range(k):
for j in range(k):
new_lock[r + i][c + j] += key[i][j]

# ์ž๋ฌผ์‡ ์— ์—ด์‡ ๊ฐ€ ๋”ฑ ๋“ค์–ด๊ฐ”๋Š”์ง€ ํ™•์ธ
if is_valid(new_lock):
return True

# ์ž๋ฌผ์‡ ์—์„œ ์—ด์‡ ๋ฅผ ๋นผ์„œ ๋ณต๊ตฌ์‹œํ‚จ๋‹ค
for i in range(k):
for j in range(k):
new_lock[r + i][c + j] -= key[i][j]
return False
6 changes: 5 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
| 34์ฐจ์‹œ | 2024.02.12 | BFS | [์ด๋ถ„ ๊ทธ๋ž˜ํ”„](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35์ฐจ์‹œ | 2024.02.18 | ๊ทธ๋ฆฌ๋”” | [์„ ๋ฌผํ• ์ธ](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) |
| 36์ฐจ์‹œ | 2024.02.21 | ์ด์ง„ํƒ์ƒ‰ | [ํœด๊ฒŒ์†Œ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) |
| 37์ฐจ์‹œ | 2024.03.04 | ๊ตฌํ˜„ | [n+1 ์นด๋“œ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
| 37์ฐจ์‹œ | 2024.03.04 | ๊ตฌํ˜„ | [n+1 ์นด๋“œ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
| 38์ฐจ์‹œ | 2024.03.08 | BRUTE_FORCE | [์ž๋ฌผ์‡ ์™€ ์—ด์‡ ](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) |
| 39์ฐจ์‹œ | 2024.03.19 | ํ | [๋””์Šคํฌ ์ปจํŠธ๋กค๋Ÿฌ](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) |
| 40์ฐจ์‹œ | 2024.03.22 | ๊ทธ๋ฆฌ๋”” | [์„ผ์„œ](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) |
| 41์ฐจ์‹œ | 2024.03.25 | ๋‹ค์ต์ŠคํŠธ๋ผ | [์•Œ๊ณ ์ŠคํŒŸ](https://www.acmicpc.net/problem/1261) | [#169](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/169) |
18 changes: 18 additions & 0 deletions pknujsp/๊ทธ๋ฆฌ๋””/40-์„ผ์„œ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sys import *

N = int(stdin.readline())
K = int(stdin.readline())
SENSORS = sorted(set(map(int, stdin.readline().split())))

if K >= N:
print(0)
exit()

distances = [SENSORS[i] - SENSORS[i - 1] for i in range(1, len(SENSORS))]
distances.sort(reverse=True)

result = 0
for i in range(K - 1, len(distances)):
result += distances[i]

print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from heapq import *
from sys import *

C, R = map(int, stdin.readline().split())
arr = [list(map(int, list(stdin.readline().strip()))) for _ in range(R)]

drc = ((1,0),(-1,0),(0,1),(0,-1))
visited = [[False] * C for _ in range(R)]
heap = [(0, 0, 0)]
target_r = R - 1
target_c = C - 1

while heap:
cost, r, c = heappop(heap)

if r == target_r and c == target_c:
print(cost)
break
if visited[r][c]:
continue

visited[r][c] = True

for dr, dc in drc:
nr = r + dr
nc = c + dc

if not 0 <= nr < R or not 0 <= nc < C:
continue
if visited[nr][nc]:
continue
Comment on lines +16 to +31
Copy link
Collaborator

@H0ngJu H0ngJu Mar 29, 2024

Choose a reason for hiding this comment

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

์ค€์„ฑ๋‹˜ ์ฝ”๋“œ ๋ณผ ๋•Œ๋งˆ๋‹ค ๋Š๋ผ๋Š”๊ฑด๋ฐ continue๋ฌธ์„ ์ž˜ ํ™œ์šฉํ•˜์‹œ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

๋งŒ์•ฝ์— visited[ ][ ]๊ฐ€ False์ธ ๊ฒฝ์šฐ์—๋งŒ 22~31๋ฒˆ์ค„์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•˜๋ฉด
์ €๋Š” if-else๋กœ ๊ตฌํ˜„ํ–ˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ continue๋ฅผ ์‚ฌ์šฉํ•˜๋‹ˆ๊นŒ ๋ณต์žกํ•œ ์ธ๋ดํŠธ๊นŒ์ง€ ์ƒ๊ฐ ์•ˆํ•ด๋„ ๋˜๋‹ˆ ์ œ ๋ˆˆ์—๋Š” ์ด๊ฒŒ ๋” ๊น”๋”ํ•ด ๋ณด์ด๋Š” ๊ฒƒ ๊ฐ™๊ธฐ๋„ ํ•˜๋„ค์š” ! ๐Ÿ˜Ž


heappush(heap, (cost + arr[nr][nc], nr, nc))
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from heapq import *
from collections import *

def solution(jobs):
jobs = deque(sorted(jobs))
jobs_num = len(jobs)

curr_time = wait_time = 0
heap = []

while heap or jobs:
while jobs and jobs[0][0] <= curr_time:
requested_time, duration = jobs.popleft()
heappush(heap, (duration, requested_time))

if heap:
duration, requested_time = heappop(heap)

curr_time += duration
wait_time += curr_time - requested_time
else:
curr_time += 1

return wait_time // jobs_num