Skip to content

Commit

Permalink
Merge pull request #124 from AlgoLeadMe/32-Munbin-Lee
Browse files Browse the repository at this point in the history
32-Munbin-Lee
  • Loading branch information
MunbinLee authored Feb 15, 2024
2 parents fce9fb7 + 1b75314 commit 429dc67
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions Munbin-Lee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
| 29์ฐจ์‹œ | 2024.01.19 | ์œ ๋‹ˆ์˜จํŒŒ์ธ๋“œ | <a href="https://www.acmicpc.net/problem/1043">๊ฑฐ์ง“๋ง</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/114 |
| 30์ฐจ์‹œ | 2024.01.23 | ์ •์ˆ˜๋ก  | <a href="https://www.acmicpc.net/problem/17425">์•ฝ์ˆ˜์˜ ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/118 |
| 31์ฐจ์‹œ | 2024.01.27 | ์ด๋ถ„ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/2143">๋‘ ๋ฐฐ์—ด์˜ ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/122 |
| 32์ฐจ์‹œ | 2024.01.30 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/17114">ํ•˜์ดํผ ํ† ๋งˆํ† </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/124 |
| 33์ฐจ์‹œ | 2024.02.04 | ์ •์ˆ˜๋ก  | <a href="https://www.acmicpc.net/problem/14905">์†Œ์ˆ˜ 4๊ฐœ์˜ ํ•ฉ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/128 |
| 34์ฐจ์‹œ | 2024.02.06 | ๊ตฌํ˜„ | <a href="https://www.acmicpc.net/problem/1756">ํ”ผ์ž ๊ตฝ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/133 |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from math import prod
from collections import deque

stdin = open(0)
sizes = list(map(int, stdin.readline().split()))
totalSize = prod(sizes)
board = []
unripe = 0
index = 0
deq = deque()

for line in stdin.read().splitlines():
for num in map(int, line.split()):
board.append(num)

if num == 0:
unripe += 1

if num == 1:
deq.append(index)

index += 1

if unripe == 0:
print('0')
exit()

def extract(x):
answer = [0] * 11
divisor = totalSize

for i in range(10, -1, -1):
divisor //= sizes[i]
answer[i] = x // divisor
x %= divisor

return answer

def compress(ls):
answer = 0
coefficient = 1

for i in range(0, 11):
answer += ls[i] * coefficient
coefficient *= sizes[i]

return answer

while deq:
cur = deq.popleft()
positions = extract(cur)

for i in range(0, 11):
for offset in (-1, 1):
positions[i] += offset

if 0 <= positions[i] < sizes[i]:
next = compress(positions)

if board[next] == 0:
board[next] = board[cur] + 1
unripe -= 1
deq.append(next)

positions[i] -= offset

if unripe == 0:
print(board[cur])
exit()

print('-1')

0 comments on commit 429dc67

Please sign in to comment.