From 3cd69c25f5e61c541633a42df1a0051c355bced2 Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Sat, 16 Mar 2024 22:20:38 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat=20:=20=EB=AC=B8=EC=9E=90=EC=97=B4=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=202=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\227\264 \352\262\214\354\236\204 2.py" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "src/main/kotlin/jimin/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.py" diff --git "a/src/main/kotlin/jimin/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.py" "b/src/main/kotlin/jimin/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.py" new file mode 100644 index 00000000..33fca0cd --- /dev/null +++ "b/src/main/kotlin/jimin/54week/\353\254\270\354\236\220\354\227\264 \352\262\214\354\236\204 2.py" @@ -0,0 +1,35 @@ +''' +[문자열 게임 2](https://www.acmicpc.net/problem/20437) +알파벳 배열을 만들어서 문자열 W의 각 문자 위치를 담았다. +이를 이용해서 해당 문자를 K개 포함할 때 최소와 최대를 업데이트 해주었다. + +''' + + +import sys + +t = int(sys.stdin.readline()) + +for i in range(t): + w = sys.stdin.readline() + k = int(sys.stdin.readline()) + + alphabet = [[] for _ in range(26)] + + for i in range(len(w) - 1): + alphabet[ord(w[i]) - ord('a')].append(i) + + mini = 10_001 + maxi = -1 + + for i in range(26): + if len(alphabet[i]) >= k: + for j in range(0, len(alphabet[i]) - k + 1): + mini = min(mini, alphabet[i][j + k - 1] - alphabet[i][j] + 1) + maxi = max(maxi, alphabet[i][j + k - 1] - alphabet[i][j] + 1) + + if maxi == -1: + print(-1) + else: + print(mini, maxi) + From b03347317be0587cb15d7f48c91e8b4906cc922b Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Sat, 16 Mar 2024 22:23:02 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat=20:=20=EC=9A=B0=EC=B2=B4=EA=B5=AD=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\232\260\354\262\264\352\265\255.py" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "src/main/kotlin/jimin/54week/\354\232\260\354\262\264\352\265\255.py" diff --git "a/src/main/kotlin/jimin/54week/\354\232\260\354\262\264\352\265\255.py" "b/src/main/kotlin/jimin/54week/\354\232\260\354\262\264\352\265\255.py" new file mode 100644 index 00000000..5f56f7dc --- /dev/null +++ "b/src/main/kotlin/jimin/54week/\354\232\260\354\262\264\352\265\255.py" @@ -0,0 +1,33 @@ +''' +[우체국](https://www.acmicpc.net/problem/2141) + +https://tussle.tistory.com/1050 블로그 참고 +왼쪽 오른쪽 사람 수가 균일한 위치를 찾는다. +이를 위해서 입력받을때 전체 사람수 total을 만들고, +마을을 순차탐색하면서 왼쪽과 오른쪽 사람의 차이가 가장 적은 위치를 구한다. + +''' + +import sys + +n = int(sys.stdin.readline()) +town = [] +total = 0 +for i in range(n): + x, a = map(int, sys.stdin.readline().split()) + total += a + town.append([x, a]) + +town.sort(key= lambda x: x[0]) + +people = 0 +mini = 1_000_000_000 * 100_000 +result = -1 +for i in range(n): + if abs(people - (total - people - town[i][1])) < mini: + mini = abs(people - (total - people - town[i][1])) + result = town[i][0] + + people += town[i][1] + +print(result) \ No newline at end of file From 31dc7501f5a568c4509b947615d988a731a5b8a9 Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Sat, 16 Mar 2024 22:23:12 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat=20:=20=ED=86=A0=EB=A7=88=ED=86=A0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\206\240\353\247\210\355\206\240.py" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "src/main/kotlin/jimin/54week/\355\206\240\353\247\210\355\206\240.py" diff --git "a/src/main/kotlin/jimin/54week/\355\206\240\353\247\210\355\206\240.py" "b/src/main/kotlin/jimin/54week/\355\206\240\353\247\210\355\206\240.py" new file mode 100644 index 00000000..fa94feb2 --- /dev/null +++ "b/src/main/kotlin/jimin/54week/\355\206\240\353\247\210\355\206\240.py" @@ -0,0 +1,43 @@ +''' +[토마토](https://www.acmicpc.net/problem/7576) + +bfs를 돌면서 토마토를 익혔으며, 이때 날짜를 업데이트 해주었다. +''' + +import sys +from collections import deque + +m, n = map(int, sys.stdin.readline().split()) +tomato = [] + +for i in range(n): + tomato.append(list(map(int, sys.stdin.readline().split()))) + +queue = deque([]) +dx = [0, 0, -1, 1] +dy = [1, -1, 0, 0] + +for i in range(n): + for j in range(m): + if tomato[i][j] == 1: + queue.append([i, j]) + +while queue: + nx, ny = queue.popleft() + + for i in range(4): + if 0 <= nx + dx[i] < n and 0 <= ny + dy[i] < m: + if tomato[nx + dx[i]][ny + dy[i]] == 0: + queue.append([nx + dx[i], ny + dy[i]]) + tomato[nx + dx[i]][ny + dy[i]] = tomato[nx][ny] + 1 + +result = 0 +for i in range(n): + for j in range(m): + if tomato[i][j] == 0: + print("-1") + sys.exit() + else: + result = max(result, tomato[i][j]) + +print(result - 1) \ No newline at end of file From 4d5959cd47ca1b819973c13c5bacb3764ea60d24 Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Sat, 16 Mar 2024 22:23:23 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat=20:=20=ED=95=AD=EC=B2=B4=20=EC=9D=B8?= =?UTF-8?q?=EC=8B=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\354\262\264 \354\235\270\354\213\235.py" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "src/main/kotlin/jimin/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.py" diff --git "a/src/main/kotlin/jimin/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.py" "b/src/main/kotlin/jimin/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.py" new file mode 100644 index 00000000..6c35b367 --- /dev/null +++ "b/src/main/kotlin/jimin/54week/\355\225\255\354\262\264 \354\235\270\354\213\235.py" @@ -0,0 +1,69 @@ +''' +[항체 인식](https://www.acmicpc.net/problem/22352) + +bfs를 만들어서 before에 맞춰서 after를 같이 탐색한다. +이때 after의 수가 일관되지 않으면 -1을 반환하고, +before와 after가 동일하면 0을 반환하고, +before와 after가 다르면 1을 반환한다. + +-1은 백신 조건을 위배한 것으로 바로 No를 출력하고, +0과 1은 계속 더해주면서 항체가 아예 변하지 않거나 한번만 변할 경우만 YES를 출력한다. +''' + + +import sys +from collections import deque + + +n, m = map(int, sys.stdin.readline().split()) +before = [] +after = [] +visited = [[False for _ in range(m)] for _ in range(n)] + +for i in range(n): + before.append(list(map(int, sys.stdin.readline().split()))) + +for i in range(n): + after.append(list(map(int, sys.stdin.readline().split()))) + + +def bfs(x, y): + queue = deque([[x, y]]) + data = before[x][y] + update = after[x][y] + dx = [0, 0, -1, 1] + dy = [1, -1, 0, 0] + possible = 0 + + if data != update: + possible = 1 + + while queue: + nx, ny = queue.popleft() + visited[nx][ny] = True + if after[nx][ny] != update: + possible = -1 + + for i in range(4): + if 0 <= nx + dx[i] < n and 0 <= ny + dy[i] < m: + if not visited[nx + dx[i]][ny + dy[i]] and before[nx + dx[i]][ny + dy[i]] == data: + queue.append([nx + dx[i], ny + dy[i]]) + + return possible + + +result = 0 +for i in range(n): + for j in range(m): + if not visited[i][j]: + possible = bfs(i, j) + if possible == -1: + print("NO") + sys.exit() + else: + result += bfs(i, j) + +if result <= 1 : + print("YES") +else: + print("NO") \ No newline at end of file