Skip to content

Commit

Permalink
22.08.08
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Aug 8, 2022
1 parent 4b633b2 commit 08857e2
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
41 changes: 41 additions & 0 deletions BAEKJOON/12906_새로운_하노이_탑.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from collections import deque
import re
import sys
def input(): return sys.stdin.readline().strip()


def move(node, a, b):
arr = node.split('/')
if len(arr[a]) == 0:
return ""
arr[b] = arr[b] + arr[a][-1]
arr[a] = arr[a][:-1]
return '/'.join(arr)


data = [input().split() for _ in range(3)]
for i in range(3):
data[i] = data[i][1] if int(data[i][0]) else ""
data = '/'.join(data)

visited = set([data])
queue = deque([(data, 0)])
while queue:
here, distance = queue.popleft()

if re.match(r'^A*/B*/C*$', here):
print(distance)
break

for i in range(3):
for j in range(3):
if i == j:
continue

there = move(here, i, j)

if there == "" or there in visited:
continue

visited.add(there)
queue.append((there, distance + 1))
48 changes: 48 additions & 0 deletions BAEKJOON/1416_팬_서비스.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import sys
def input(): return sys.stdin.readline().strip()


def make_cnt(nums, k):
if k == 0:
return {0: 1}

if k == 1:
retval = {}
for num in nums:
retval[num] = 1
return retval

retval, arr = {}, make_cnt(nums, k // 2)
for a, ac in arr.items():
for b, bc in arr.items():
retval[a + b] = (retval.get(a + b, 0) + ac * bc) % MOD

if k % 2 == 0:
return retval

retval, arr = {}, retval
for a, ac in arr.items():
for num in nums:
retval[a + num] = (retval.get(a + num, 0) + ac) % MOD
return retval


MOD = 999_983
K = int(input())
data = sorted(list(map(int, input())))

answer = 0
cnt = make_cnt(data, K)
for v in cnt.values():
answer = (answer + v ** 2) % MOD
answer = (2 * answer) % MOD

minus = 1
for i in range(K, K + 2):
cnt = make_cnt(data, i // 2)
temp = 0
for v in cnt.values():
temp = (temp + v ** 2) % MOD
minus = minus * temp
answer = (answer - minus + MOD) % MOD
print(answer)
43 changes: 43 additions & 0 deletions BAEKJOON/2288_격자의_분리자.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys
def input(): return sys.stdin.readline().strip()

dx = [0, 1, -1]
dy = [1, 0, 0]

while True:
N, M = map(int, input().split())
if N == 0:
break
data = [input() for _ in range(N)]

x, y = -1, 0
for i in range(0, M):
if data[0][i] == 'S':
x = i
break

px, py, pi, ppi = -1, -1, -1, -1
answer = 1
while True:
for i in range(3):
nx, ny = x + dx[i], y + dy[i]
if nx < 0 or nx >= M or ny < 0 or ny >= N:
continue
if nx == px and ny == py:
continue
if data[ny][nx] != 'S':
continue

if pi or (i == 0 or i == ppi):
answer = answer + 1
else:
ppi = i

px, py, pi = x, y, i
x, y = nx, ny
break

else:
break

print(answer)

0 comments on commit 08857e2

Please sign in to comment.