From 8e6456064bb4f1978b7e6caf7ea18801ef25ebee Mon Sep 17 00:00:00 2001 From: kyu-hyun <102718303+lalabulla@users.noreply.github.com> Date: Sun, 8 Oct 2023 01:31:12 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Create=20=EB=B6=88!=20kyuhyun.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\266\210!/kyuhyun.py" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\353\266\210!/kyuhyun.py" diff --git "a/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\353\266\210!/kyuhyun.py" "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\353\266\210!/kyuhyun.py" new file mode 100644 index 0000000..da4c2b0 --- /dev/null +++ "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\353\266\210!/kyuhyun.py" @@ -0,0 +1,43 @@ +from collections import deque + +n, m = map(int, input().split()) +map = [] +ans = 'IMPOSSIBLE' + +for i in range(n): + map.append(list(input())) + if 'J' in map[i]: + q = deque([(0, i, map[i].index('J'))]) + +for i in range(n): + for j in range(m): + if map[i][j] == 'F': + q.append((-1, i, j)) + +dx = [-1, 1, 0, 0] +dy = [0, 0, -1, 1] + +while q: + time, x, y = q.popleft() + + # 지훈이 탈출 + if time > -1 and map[x][y] != 'F': + if x == 0 or y == 0 or x == n - 1 or y == m - 1: + ans = time + 1 + break + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if 0 <= nx < n and 0 <= ny < m and map[nx][ny] != '#': + # 지훈이 이동 + if time > -1 and map[nx][ny] == '.': + map[nx][ny] = '*' + q.append((time + 1, nx, ny)) + # 불 퍼뜨리기 + elif time == -1 and map[nx][ny] != 'F': + map[nx][ny] = 'F' + q.append((-1, nx, ny)) + +print(ans) From 28885e28b8bf574472212e5d3931403bd19adcd1 Mon Sep 17 00:00:00 2001 From: kyu-hyun <102718303+lalabulla@users.noreply.github.com> Date: Sun, 8 Oct 2023 01:32:23 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Create=20=EC=B9=98=ED=82=A8=20=EB=B0=B0?= =?UTF-8?q?=EB=8B=AC=20kyuhyun.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kyuhyun.py" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/kyuhyun.py" diff --git "a/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/kyuhyun.py" "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/kyuhyun.py" new file mode 100644 index 0000000..b99b611 --- /dev/null +++ "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\271\230\355\202\250 \353\260\260\353\213\254/kyuhyun.py" @@ -0,0 +1,32 @@ +from itertools import combinations + +n, m = map(int, input().split(" ")) + +city = [] + +for _ in range(n) : + tmp = list(map(int, input().split(" "))) + city.append(tmp) + +res = 99999 +home = [] +chick = [] + +for i in range(n): + for j in range(n): + if city[i][j] == 1: + home.append([i, j]) + continue + if city[i][j] == 2: + chick.append([i, j]) + +for c in combinations(chick, m): + total_chick = 0 + for h in home: + len_chick = 999 + for i in range(m): + len_chick = min(len_chick, abs(c[i][0]-h[0]) + abs(c[i][1]-h[1])) + total_chick += len_chick + res = min(total_chick, res) +print(res) + From dee0c4c737acbf0af3453f7b2074ded92c55ba61 Mon Sep 17 00:00:00 2001 From: kyu-hyun <102718303+lalabulla@users.noreply.github.com> Date: Sun, 8 Oct 2023 10:10:13 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Create=20=EC=8A=A4=ED=83=80=ED=8A=B8?= =?UTF-8?q?=EC=99=80=20=EB=A7=81=ED=81=AC=20kyuhyun.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kyuhyun.py" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254/kyuhyun.py" diff --git "a/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254/kyuhyun.py" "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254/kyuhyun.py" new file mode 100644 index 0000000..fc13bc1 --- /dev/null +++ "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\354\212\244\355\203\200\355\212\270\354\231\200 \353\247\201\355\201\254/kyuhyun.py" @@ -0,0 +1,29 @@ +from itertools import combinations, permutations +n = int(input()) + +sal = [] +people = [] +result = 99999 + +for i in range(n): + sal.append(list(map(int, input().split(" ")))) + people.append(i) + +for team_s in combinations(people, n//2): + + team_l = [] + total_stark = 0 + total_link = 0 + + for i in range(n): + if i not in team_s: + team_l.append(i) + + for power_s in permutations(team_s, 2): + total_stark += sal[power_s[0]][power_s[1]] + + for power_l in permutations(team_l, 2): + total_link += sal[power_l[0]][power_l[1]] + + result = min(result, abs(total_stark - total_link)) +print(result) From da6c3f24b937d351da8275b40b68ae4746dd7900 Mon Sep 17 00:00:00 2001 From: kyu-hyun <102718303+lalabulla@users.noreply.github.com> Date: Sun, 8 Oct 2023 10:11:03 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Create=20=ED=86=A0=EB=A7=88=ED=86=A0=20kyuh?= =?UTF-8?q?yun.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kyuhyun.py" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\355\206\240\353\247\210\355\206\240/kyuhyun.py" diff --git "a/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\355\206\240\353\247\210\355\206\240/kyuhyun.py" "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\355\206\240\353\247\210\355\206\240/kyuhyun.py" new file mode 100644 index 0000000..1f4529c --- /dev/null +++ "b/Baekjoon - \353\254\270\354\240\234\355\222\200\354\235\264/\355\206\240\353\247\210\355\206\240/kyuhyun.py" @@ -0,0 +1,46 @@ +from collections import deque +m, n = map(int, input().split(" ")) + +tomato = [] +q = deque() +flag = 0 + +for _ in range(n) : + tmp = list(map(int, input().split(" "))) + tomato.append(tmp) + +dx = [1, -1, 0, 0] +dy = [0, 0, 1, -1] + +def bfs(): + global res + while q: + time, y, x = q.popleft() + res = time + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if nx < 0 or nx >= m or ny < 0 or ny >= n: + continue + if tomato[ny][nx] == 1 or tomato[ny][nx] == -1: + continue + q.append([time + 1, ny, nx]) + tomato[ny][nx] = 1 + +for i in range(n): + for j in range(m): + if tomato[i][j] == 1: + q.append([0, i, j]) +bfs() +for i in range(n): + if 0 in tomato[i]: + flag = 1 + break + +if flag == 1: + print(-1) +else: + print(res) +