From f08fa1272dcbf7af7925671a1e71a7bda8c9b24a Mon Sep 17 00:00:00 2001 From: yang Date: Fri, 22 Sep 2023 19:00:52 +0900 Subject: [PATCH 01/15] =?UTF-8?q?11=EC=A3=BC=EC=B0=A8=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wonjoon/week11/RGB.java | 31 ++++++++++++++++++++ wonjoon/week11/Tall.java | 61 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 wonjoon/week11/RGB.java create mode 100644 wonjoon/week11/Tall.java diff --git a/wonjoon/week11/RGB.java b/wonjoon/week11/RGB.java new file mode 100644 index 0000000..14a3dc4 --- /dev/null +++ b/wonjoon/week11/RGB.java @@ -0,0 +1,31 @@ +package week11; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class RGB { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int n; + static int[][] houseValues; + public static void main(String[] args) throws IOException { + n = Integer.parseInt(br.readLine()); + houseValues = new int[n][3]; + + for (int i = 0; i < n; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + houseValues[i][0] = Integer.parseInt(st.nextToken()); + houseValues[i][1] = Integer.parseInt(st.nextToken()); + houseValues[i][2] = Integer.parseInt(st.nextToken()); + } + + for (int i = 1; i < n; i++) { + houseValues[i][0] = Math.min(houseValues[i-1][1], houseValues[i-1][2]) + houseValues[i][0]; + houseValues[i][1] = Math.min(houseValues[i-1][0], houseValues[i-1][2]) + houseValues[i][1]; + houseValues[i][2] = Math.min(houseValues[i-1][0], houseValues[i-1][1]) + houseValues[i][2]; + } + + System.out.println(Math.min(houseValues[n-1][0], Math.min(houseValues[n-1][1], houseValues[n-1][2]))); + } +} diff --git a/wonjoon/week11/Tall.java b/wonjoon/week11/Tall.java new file mode 100644 index 0000000..e4837c6 --- /dev/null +++ b/wonjoon/week11/Tall.java @@ -0,0 +1,61 @@ +package week11; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Tall { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static boolean[][] check; // 이어져있는지 + static int N, M; + + public static void main(String[] args) throws Exception { + int answer = 0; + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + check = new boolean[N][N]; + for (int i = 0; i < N; i++) + Arrays.fill(check[i], false); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()) - 1; + int to = Integer.parseInt(st.nextToken()) - 1; + check[from][to] = true; + } + + for (int k = 0; k < N; k++) { // 경유지 + for (int i = 0; i < N; i++) { // 출발지 + for (int j = 0; j < N; j++) { // 도착지 + if (k == i || i == j || k == j) + continue; + if (check[i][j]) + continue; + if (check[i][k] == true && check[k][j] == true) + check[i][j] = true; + // 한단계씩 갈 수 있는지 체크 갈 수 있다면 true + } + } + } + + for (int i = 0; i < N; i++) { + boolean flag = true; + for (int j = 0; j < N; j++) { + if (i == j || check[i][j] || check[j][i]) + continue; + // n번이 m번까지 모두 연결되어있다면 계속 continue하여 flag가 true + flag = false; + break; + + } + if (flag) + answer++; + } + System.out.println(answer); + } +} From ef42a8171401912098448fc51c8eb4e204f5f31d Mon Sep 17 00:00:00 2001 From: does Date: Thu, 28 Sep 2023 15:32:28 +0900 Subject: [PATCH 02/15] 1043 solve --- dongkyu/week13/1043.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 dongkyu/week13/1043.py diff --git a/dongkyu/week13/1043.py b/dongkyu/week13/1043.py new file mode 100644 index 0000000..d413edf --- /dev/null +++ b/dongkyu/week13/1043.py @@ -0,0 +1,28 @@ +import sys + + +def solve(knowing, parties): + truth = [1] * m + while True: + knowing_changed = False + for i in range(m): + has_knowing = False + if truth[i] == 0: + continue + for p in parties[i]: + if p in knowing: + truth[i] = 0 + has_knowing = True + if has_knowing: + knowing |= set(parties[i]) + knowing_changed = True + + if not knowing_changed: + break + return sum(truth) + + +n, m = map(int, sys.stdin.readline().split()) +knowing = set(list(map(int, sys.stdin.readline().split()))[1:]) +parties = [list(map(int, input().split()))[1:] for _ in range(m)] +print(solve(knowing, parties)) From 605d964a4c4f9d3d6e0b21fd021f1e1a74be2bc2 Mon Sep 17 00:00:00 2001 From: does Date: Thu, 28 Sep 2023 18:32:02 +0900 Subject: [PATCH 03/15] 15686 solve --- dongkyu/week13/15686.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 dongkyu/week13/15686.py diff --git a/dongkyu/week13/15686.py b/dongkyu/week13/15686.py new file mode 100644 index 0000000..baffde4 --- /dev/null +++ b/dongkyu/week13/15686.py @@ -0,0 +1,31 @@ +import sys +from itertools import combinations +from collections import deque + + +def solve(n, m, board): + chickens = [] + homes = [] + for i in range(n): + for j in range(n): + if board[i][j] == 2: + chickens.append((i, j)) + elif board[i][j] == 1: + homes.append((i, j)) + + combs = list(combinations(chickens, m)) + dists = [] + for comb in combs: + dists.append(0) + for x, y in homes: + dist = int(1e9) + for r, c in comb: + dist = min(dist, abs(x - r) + abs(y - c)) + dists[-1] += dist + + return min(dists) + + +N, M = map(int, sys.stdin.readline().split()) +BOARD = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)] +print(solve(N, M, BOARD)) From 3607f7a37d1f2b59d5e559a8dff4f78fda702e1d Mon Sep 17 00:00:00 2001 From: does Date: Fri, 29 Sep 2023 00:03:32 +0900 Subject: [PATCH 04/15] 17070 solve --- dongkyu/week13/17070.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 dongkyu/week13/17070.py diff --git a/dongkyu/week13/17070.py b/dongkyu/week13/17070.py new file mode 100644 index 0000000..373c82c --- /dev/null +++ b/dongkyu/week13/17070.py @@ -0,0 +1,26 @@ +import sys + + +def solve(n, board): + right, down, diagonal = 0, 1, 2 + dp = [[[0 for _ in range(N)] for _ in range(N)] for _ in range(3)] + dp[right][0][1] = 1 + for i in range(2, n): + if board[0][i] == 0: + dp[right][0][i] = dp[right][0][i - 1] + + for r in range(1, n): + for c in range(1, n): + if board[r][c] == 0 and board[r][c - 1] == 0 and board[r - 1][c] == 0: + for i in range(3): + dp[diagonal][r][c] += dp[i][r - 1][c - 1] + + if board[r][c] == 0: + dp[right][r][c] = dp[right][r][c - 1] + dp[diagonal][r][c - 1] + dp[down][r][c] = dp[down][r - 1][c] + dp[diagonal][r - 1][c] + return dp[right][n - 1][n - 1] + dp[down][n - 1][n - 1] + dp[diagonal][n - 1][n - 1] + + +N = int(sys.stdin.readline()) +BOARD = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)] +print(solve(N, BOARD)) From 11c43fec2397b49acd04cdc1657a8c215446b911 Mon Sep 17 00:00:00 2001 From: JINU-CHANG Date: Wed, 4 Oct 2023 21:17:57 +0900 Subject: [PATCH 05/15] 15686, 1043 solve --- .DS_Store | Bin 6148 -> 8196 bytes jinwoo/week13/B_1043.java | 97 +++++++++++++++++++++++++++++++++++++ jinwoo/week13/B_15686.java | 96 ++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 jinwoo/week13/B_1043.java create mode 100644 jinwoo/week13/B_15686.java diff --git a/.DS_Store b/.DS_Store index 76f22eb8c19a2226094326cf45d607e1c49a82c5..55042f4520be5a51c8ce3745c8053849639a66cd 100644 GIT binary patch literal 8196 zcmeHMO=}ZD7=EWsvRjK7v_ieD6pDvZ(<&{+ON`M&!HcPSsHJ9`&~BUT#C$ZCS_oeJ zLi`KTlfS?ZMDSqopr9u&UV5!w`~iZ#^O4QWCaWj0&>7fyH}gI-?~`X{-^pwMfMgnl z34mb$u<>FxIfzw{!u;&&Dt)qL5-q|0P+FeIEzxqN3uzjR0!9I&fKk9GU=-Ld3gDj2 ziXE}<3$Lk-0!D!YsQ}9l4qnWrrELkzQwLW32!J+*&Ai}!lHH(nq)kiP5*9sJi0Fz| zbS3hLK}2_KcO)(?ZA)0u9f&-95E+@s6AIzcaeRlvfuw~swNbz*(5(PFyT@Q0mcfI% zc7Bf^y{h`kG@Erx)WtS?>8JJhl)H0Y_ZR-?udFEV2JENU6|8n#Sb+w(T6E}p*Nsp) z+&!`P>&ZOl5E`dUJ4~Wc8Xu8t;>gE?0u&*ybFuFu7sadccs&~M&=4ICy%Bo+R9laA zsKF9Y#zN-+Gg1!)q4Kyl|8?l3m=mUlhU##MM(KQb7PXKC1s~VO8f-vA=d&=%`Dh50 z&+LOhm(V!s{6wQPJ|fvCU=`=bhbFS3ZnIXA>+z*qDS5SeD)oi*^~d4~%eL%6dm*<% zo4Ib0@1!gI>Ur3&>YI3W#GA|W^{0j|d)=8F)M%iG8#giyJ>xD{~eLUo>x zXq3hW-eNG!2wV|-Vnffy$64L0@)&s^@KE}ziu6Wk@rjIILnV4>vBR{8BQNPyN%#W&fl;)&(Dmf z#WRMF*#q-Nc-`#9yAdk4jZXo$&^RiqXq3)pm+{#zrC$&kX6OHl(eMBF3thv*C}0%$ z2MUl_HkZxd!0jI@;TUZDb?~~07b^_c5|($tia}UAKaQgf{xHOQNBYvzwuD6wmjCb~ S!0i9x++_BDTz?03|Njk~;C251 delta 144 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjdE!6q~50D9QxlfW`6|@{`Jo3zBm3lO`rE zpKKt*GI_hu!^sLF{2Nm^*cP*Ma0oI36$60)H;`}z8L~0)JM(0I8A}C_Fwhu~X&{;f SL<2b>>p(7G*c{I@hZz6_Cl*Tp diff --git a/jinwoo/week13/B_1043.java b/jinwoo/week13/B_1043.java new file mode 100644 index 0000000..442650e --- /dev/null +++ b/jinwoo/week13/B_1043.java @@ -0,0 +1,97 @@ +package jinwoo.week13; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/* + * union-find 를 이용하여 루트 노드가 진실을 아는 사람으로 이루어진 그룹을 피한다. + * 1. M개의 모든 파티들을 조회하여 진실을 아는 사람이 파티원에 속해있다면 + * 그 파티원을 루트 노드로 설정하여 집합을 만든다. + * 2. 모든 집합이 형성된 후, 다시 M개의 모든 파티를 조회하여 루트 노드가 + * 진실이 아닌 파티들을 카운트해주면 된다. + */ + +public class B_1043 { + static int N, M; + static int[] parents; // 루트 노드 저장 + static List tList; // 진실을 아는 사람들 + public static void main(String[] args) throws IOException { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); // 사람 수 + M = Integer.parseInt(st.nextToken()); // 파티 수 + + parents = new int[N+1]; // 자기 자신을 루트로 하는 배열을 생성한다. + for(int i=1; i(); + if(tn==0) { // 진실을 아는 사람이 없을 때 + System.out.println(M); // 파티 수 그대로 반환 + return; + } else{ + for(int i=0; i[] partyList = new ArrayList[M]; // 파티 정보 + for(int i=0; i(); + } + + for(int i=0; i house = new ArrayList<>(); // 집 좌표 저장 + static ArrayList chicken = new ArrayList<>(); // 치킨집 좌표 저장 + static Integer ans = Integer.MAX_VALUE; + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + // 집과 치킨집 좌표 저장 + for(int i=0; i Date: Thu, 5 Oct 2023 14:58:14 +0900 Subject: [PATCH 06/15] 9935 solve --- dongkyu/9935.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 dongkyu/9935.py diff --git a/dongkyu/9935.py b/dongkyu/9935.py new file mode 100644 index 0000000..c53be0c --- /dev/null +++ b/dongkyu/9935.py @@ -0,0 +1,22 @@ +import sys +from collections import deque + + +def solve(s, b): + stack = deque() + n, m = len(s), len(b) + burst = deque(b) + for i in range(n): + stack.append(s[i]) + if stack and stack[-1] == b[-1] and len(stack) >= len(b): + temp = deque() + for _ in range(m): + temp.appendleft(stack.pop()) + if temp != burst: + stack.extend(temp) + return ''.join(stack) if len(stack) > 0 else 'FRULA' + + +S = sys.stdin.readline().strip() +B = sys.stdin.readline().strip() +print(solve(S, B)) From 30c0910febd2a564765be05c790a60eb32a8c192 Mon Sep 17 00:00:00 2001 From: does Date: Fri, 6 Oct 2023 16:52:50 +0900 Subject: [PATCH 07/15] 10830 solve --- dongkyu/week14/10830.py | 27 +++++++++++++++++++++++++++ dongkyu/{ => week14}/9935.py | 0 2 files changed, 27 insertions(+) create mode 100644 dongkyu/week14/10830.py rename dongkyu/{ => week14}/9935.py (100%) diff --git a/dongkyu/week14/10830.py b/dongkyu/week14/10830.py new file mode 100644 index 0000000..3bcab3f --- /dev/null +++ b/dongkyu/week14/10830.py @@ -0,0 +1,27 @@ +import sys + + +def cal(n, a, b): + result = [[0] * n for _ in range(n)] + for i in range(n): + for j in range(n): + for k in range(n): + result[i][j] += a[i][k] * b[k][j] + result[i][j] %= 1000 + return result + + +def solve(n, b, matrix): + if b == 0: + return [[1 if a == b else 0 for a in range(n)] for b in range(n)] + elif b % 2 == 0: + half = solve(n, b // 2, matrix) + return cal(n, half, half) + else: + return cal(n, matrix, solve(n, b - 1, matrix)) + + +N, B = map(int, sys.stdin.readline().split(' ')) +M = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)] +for res in solve(N, B, M): + print(' '.join(map(str, res))) diff --git a/dongkyu/9935.py b/dongkyu/week14/9935.py similarity index 100% rename from dongkyu/9935.py rename to dongkyu/week14/9935.py From 72f29344491eeb26513dcd3f169de1b7e57e52a9 Mon Sep 17 00:00:00 2001 From: does Date: Sat, 7 Oct 2023 14:34:51 +0900 Subject: [PATCH 08/15] 11404 solve --- dongkyu/week14/11404.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dongkyu/week14/11404.py diff --git a/dongkyu/week14/11404.py b/dongkyu/week14/11404.py new file mode 100644 index 0000000..c3c3116 --- /dev/null +++ b/dongkyu/week14/11404.py @@ -0,0 +1,37 @@ +import sys +from collections import defaultdict +import heapq as hq + + +def solve(n, info): + dist = [[int(1e9)] * (n + 1) for _ in range(n + 1)] + graph = defaultdict(list) + for a, b, c in info: + graph[a].append((b, c)) + + for start in range(1, n + 1): + dist[start][start] = 0 + queue = [] + hq.heappush(queue, (dist[start][start], start)) + + while queue: + current_dist, current_node = hq.heappop(queue) + + if dist[start][current_node] < current_dist: + continue + + for next_node, next_dist in graph[current_node]: + new_dist = current_dist + next_dist + if new_dist < dist[start][next_node]: + dist[start][next_node] = new_dist + hq.heappush(queue, (new_dist, next_node)) + return dist + + +N = int(sys.stdin.readline()) +M = int(sys.stdin.readline()) +INFO = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(M)] +result = solve(N, INFO) +for i in range(1, N + 1): + print(' '.join(map(str, [result[i][j] if result[i][j] < int(1e9) else 0 for j in range(1, N + 1)]))) + From 10786b2b97f076ec47a2159c147734402684d88a Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 11 Oct 2023 00:38:43 +0900 Subject: [PATCH 09/15] =?UTF-8?q?14=EC=A3=BC=EC=B0=A8=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wonjoon/week14/B_10830.java | 93 +++++++++++++++++++++++++++++++++++++ wonjoon/week14/B_11404.java | 60 ++++++++++++++++++++++++ wonjoon/week14/B_9935.java | 73 +++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 wonjoon/week14/B_10830.java create mode 100644 wonjoon/week14/B_11404.java create mode 100644 wonjoon/week14/B_9935.java diff --git a/wonjoon/week14/B_10830.java b/wonjoon/week14/B_10830.java new file mode 100644 index 0000000..8011710 --- /dev/null +++ b/wonjoon/week14/B_10830.java @@ -0,0 +1,93 @@ +package week14; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class B_10830 { + static long[][] origin; + static long[][] matrix; + static long[][] temp; + static int n; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + long b = Long.parseLong(st.nextToken()); + + origin = new long[n][n]; + matrix = new long[n][n]; + temp = new long[n][n]; + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < n; j++) { + matrix[i][j] = Integer.parseInt(st.nextToken()); + temp[i][j] = matrix[i][j]; + origin[i][j] = matrix[i][j]; + } + } + + matrixSum(b); + +// int cnt = 1; +// int sum; +// while (cnt < b) { +// for (int i = 0; i < n; i++) { +// for (int j = 0; j < n; j++) { +// sum = 0; +// for (int k = 0; k < n; k++) { +// sum += matrix[i][k]*origin[k][j]; +// } +// temp[i][j] = sum; +// } +// } +// for (int i = 0; i < n; i++) { +// for (int j = 0; j < n; j++) { +// matrix[i][j] = temp[i][j]; +// } +// } +// cnt++; +// } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + System.out.print(matrix[i][j]%1000 + " "); + } + System.out.println(); + } + } + + static void matrixSum(long b) { + if (b == 0) + return; + matrixSum(b/2); + if (b == 1) + return; + if (b%2 == 1) { + multi(matrix); + multi(origin); + return; + } + multi(matrix); + } + + static void multi(long[][] matrix2) { + long sum; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + sum = 0; + for (int k = 0; k < n; k++) { + sum += matrix[i][k]*matrix2[k][j]; + } + temp[i][j] = sum % 1000; + } + } + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + matrix[i][j] = temp[i][j]; + } + } + } +} diff --git a/wonjoon/week14/B_11404.java b/wonjoon/week14/B_11404.java new file mode 100644 index 0000000..61f361b --- /dev/null +++ b/wonjoon/week14/B_11404.java @@ -0,0 +1,60 @@ +package week14; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class B_11404 { + static int n; + static int bus; + static long adjMat[][]; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + n = Integer.parseInt(br.readLine()); + bus = Integer.parseInt(br.readLine()); + adjMat = new long[n+1][n+1]; + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == j) { + adjMat[i][j] = 0; + continue; + } + adjMat[i][j] = Integer.MAX_VALUE; + } + } + + for (int i = 0; i < bus; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + if (adjMat[a][b] > c) + adjMat[a][b] = c; + } + + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == j) + continue; + if (adjMat[i][k] != Integer.MAX_VALUE && adjMat[k][j] != Integer.MAX_VALUE) { + if (adjMat[i][j] > (adjMat[i][k] + adjMat[k][j])) + adjMat[i][j] = (adjMat[i][k] + adjMat[k][j]); + } + } + } + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (adjMat[i][j] == Integer.MAX_VALUE) + adjMat[i][j] = 0; + System.out.print(adjMat[i][j] + " "); + } + System.out.println(); + } + } +} diff --git a/wonjoon/week14/B_9935.java b/wonjoon/week14/B_9935.java new file mode 100644 index 0000000..e7cc39e --- /dev/null +++ b/wonjoon/week14/B_9935.java @@ -0,0 +1,73 @@ +package week14; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class B_9935 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String st = br.readLine(); + String bomb = br.readLine(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < st.length(); i++) { + sb.append(st.charAt(i)); + if (sb.length() >= bomb.length()) { + if (sb.substring(sb.length()-bomb.length(), sb.length()).equals(bomb)) { + sb.delete(sb.length()-bomb.length(), sb.length()); + } + } + } + + Runtime.getRuntime().gc(); + long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); + System.out.println(usedMemory + " bytes"); + + if (sb.length() == 0) { + System.out.println("FRULA"); + return; + } + System.out.println(sb); + } +} + +/** + * import java.io.BufferedReader; + * import java.io.IOException; + * import java.io.InputStreamReader; + * + * public class Main { + * static String st; + * public static void main(String[] args) throws IOException { + * BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + * + * st = br.readLine(); + * String bomb = br.readLine(); + * + * while (checkBomb(bomb)) + * // while(true) { + * // String s = checkBomb(bomb); + * // if (s.equals("FIN")) + * // break; + * // st = s; + * // } + * + * if (st.isEmpty()) { + * System.out.println("FRULA"); + * return; + * } + * System.out.println(st); + * } + * + * private static boolean checkBomb(String bomb) { + * if (st.contains(bomb)) { + * st = st.replace(bomb, ""); + * return true; + * } + * return false; + * } + * } + * + * 메모리 초과 + */ From fb8b1ca0a7cb929f8ef1bc7c7e90b4e20d793824 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Wed, 11 Oct 2023 21:25:34 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[14=EC=A3=BC=EC=B0=A8]=20=EC=95=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=EC=A6=98-=EC=9E=A5=EC=84=B8=EC=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\241\234\354\235\264\353\223\234.java" | 49 +++++++++++++++++++ ...354\227\264 \355\217\255\353\260\234.java" | 43 ++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 "seeun/week14/11404 \355\224\214\353\241\234\354\235\264\353\223\234.java" create mode 100644 "seeun/week14/9935 \353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234.java" diff --git "a/seeun/week14/11404 \355\224\214\353\241\234\354\235\264\353\223\234.java" "b/seeun/week14/11404 \355\224\214\353\241\234\354\235\264\353\223\234.java" new file mode 100644 index 0000000..eaa2dfe --- /dev/null +++ "b/seeun/week14/11404 \355\224\214\353\241\234\354\235\264\353\223\234.java" @@ -0,0 +1,49 @@ +import java.io.*; +import java.util.*; + +public class Main { + + static int[][] arr; + + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + int m = Integer.parseInt(br.readLine()); + + // 최솟값을 구하기 때문에 먼저 최댓값으로 채우기 + arr = new int[n + 1][n + 1]; + for(int i = 1; i <= n; i++) { + for(int j = 1; j <= n; j++) { + arr[i][j] = 100000001; + } + arr[i][i] = 0; + } + + for(int i = 0; i < m; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + if(arr[start][end] > cost) arr[start][end] = cost; + } + + //플로이드-워샬알고리즘 + for(int k = 1; k < n + 1; k++) { + for(int i = 1; i < n + 1; i++) { + for(int j = 1; j < n + 1; j++) { + if(arr[i][j] > arr[i][k] + arr[k][j]) + arr[i][j] = arr[i][k] + arr[k][j]; + } + } + } + + for(int i = 1; i < n + 1; i++) { + for(int j = 1; j < n + 1; j++) { + //i -> j로 갈 수 없는 경우 0출력 + if(arr[i][j] == 100000001) System.out.print("0 "); + else System.out.print(arr[i][j] + " "); + } + System.out.println(); + } + } +} \ No newline at end of file diff --git "a/seeun/week14/9935 \353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234.java" "b/seeun/week14/9935 \353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234.java" new file mode 100644 index 0000000..ca3478e --- /dev/null +++ "b/seeun/week14/9935 \353\254\270\354\236\220\354\227\264 \355\217\255\353\260\234.java" @@ -0,0 +1,43 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String str = br.readLine(); + String bomb = br.readLine(); + int bombSize = bomb.length(); + + Stack st = new Stack<>(); + + for(int i = 0; i < str.length(); i++) { + st.push(str.charAt(i)); + + // 폭발 문자열과 길이가 같아지면 탐색 시작 + if(st.size() >= bombSize) { + boolean isSame = true; + + //bomb와 일치하면 제거 + for(int j = 0; j < bombSize; j++) { + if(st.get(st.size() - bombSize + j) != bomb.charAt(j)) { + isSame = false; + continue; + } + } + if(isSame) { + for(int j = 0; j < bombSize; j++) { + st.pop(); + } + } + } + + } + + //StringBuilder 사용 안하면 시간초과 발생 + StringBuilder sb = new StringBuilder(); + for(Character c : st) { + sb.append(c); + } + System.out.println(sb.length()==0? "FRULA" : sb.toString()); + } +} \ No newline at end of file From f596129de7db1e2891368d4c2b99ebf5d2316ec0 Mon Sep 17 00:00:00 2001 From: does Date: Wed, 11 Oct 2023 23:20:49 +0900 Subject: [PATCH 11/15] 2166 solve --- dongkyu/week15/2166.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dongkyu/week15/2166.py diff --git a/dongkyu/week15/2166.py b/dongkyu/week15/2166.py new file mode 100644 index 0000000..e44a7dc --- /dev/null +++ b/dongkyu/week15/2166.py @@ -0,0 +1,15 @@ +import sys + + +def solve(n, points): + answer = 0 + for i in range(n): + x1, y1 = points[i] + x2, y2 = points[(i + 1) % n] + answer += (x1 * y2 - x2 * y1) + return round(abs(answer) / 2, 1) + + +N = int(sys.stdin.readline()) +P = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)] +print(solve(N, P)) From a191d4651f33aed411ea66ac8b67008c3f94ad45 Mon Sep 17 00:00:00 2001 From: does Date: Thu, 12 Oct 2023 17:01:43 +0900 Subject: [PATCH 12/15] 2239 solve --- dongkyu/week15/2239.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 dongkyu/week15/2239.py diff --git a/dongkyu/week15/2239.py b/dongkyu/week15/2239.py new file mode 100644 index 0000000..c2aec48 --- /dev/null +++ b/dongkyu/week15/2239.py @@ -0,0 +1,34 @@ +import sys + + +def valid(num, x, y, board): + k = 0 + lx, ly = x // 3 * 3, y // 3 * 3 + for i in range(lx, lx + 3): + for j in range(ly, ly + 3): + if board[i][j] == num or board[x][k] == num or board[k][y] == num: + return False + k += 1 + return True + + +def search(board, blanks, idx): + if len(blanks) == idx: + for b in board: + print(''.join(map(str, b))) + exit() + + x, y = blanks[idx] + for num in range(1, 10): + if valid(num, x, y, board): + board[x][y] = num + search(board, blanks, idx + 1) + board[x][y] = 0 + + +def solve(board): + blanks = [(i, j) for i in range(9) for j in range(9) if board[i][j] == 0] + search(board, blanks, 0) + + +solve([list(map(int, sys.stdin.readline().strip())) for _ in range(9)]) From c60a2325ba9d95e320de3ab5775c58db582917a7 Mon Sep 17 00:00:00 2001 From: does Date: Sat, 14 Oct 2023 13:45:53 +0900 Subject: [PATCH 13/15] 1647 solve --- dongkyu/week15/1647.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 dongkyu/week15/1647.py diff --git a/dongkyu/week15/1647.py b/dongkyu/week15/1647.py new file mode 100644 index 0000000..69515a3 --- /dev/null +++ b/dongkyu/week15/1647.py @@ -0,0 +1,24 @@ +import sys + + +def find(v, parents): + if v != parents[v]: + parents[v] = find(parents[v], parents) + return parents[v] + + +def solve(n, roads): + sum_cost, max_cost = 0, 0 + parents = [0] + [i for i in range(1, n + 1)] + for s, d, c in sorted(roads, key=lambda x: x[2]): + sp, dp = find(s, parents), find(d, parents) + if sp != dp: + sum_cost += c + max_cost = max(max_cost, c) + parents[max(sp, dp)] = min(sp, dp) + return sum_cost - max_cost + + +N, M = map(int, sys.stdin.readline().split(' ')) +R = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(M)] +print(solve(N, R)) From 407057f9b2873b3ba09d2957e74dbf68b97765dd Mon Sep 17 00:00:00 2001 From: seeunjang Date: Wed, 18 Oct 2023 21:03:45 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[15=EC=A3=BC=EC=B0=A8]=20=EC=95=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=EC=A6=98=20-=20=EC=9E=A5=EC=84=B8=EC=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" | 0 ...213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 "seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" create mode 100644 "seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" diff --git "a/seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" "b/seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" new file mode 100644 index 0000000..e69de29 diff --git "a/seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" "b/seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" new file mode 100644 index 0000000..e69de29 From 3f4b5e8f0b718618384270a75e0af4f655f816ef Mon Sep 17 00:00:00 2001 From: seeunjang Date: Wed, 18 Oct 2023 22:06:07 +0900 Subject: [PATCH 15/15] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\240\352\263\204\355\232\215.java" | 93 +++++++++++++++++++ ...355\230\225 \353\251\264\354\240\201.java" | 24 +++++ 2 files changed, 117 insertions(+) diff --git "a/seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" "b/seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" index e69de29..e5dc765 100644 --- "a/seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" +++ "b/seeun/week15/1647 \353\217\204\354\213\234\353\266\204\355\225\240\352\263\204\355\232\215.java" @@ -0,0 +1,93 @@ +import java.io.*; +import java.util.*; + +public class Main { + private static int n, m; + private static int[] parent; + private static PriorityQueue pq; + + private static class Node implements Comparable{ + int a, b, c; + + Node(int a ,int b, int c){ + this.a = a; + this.b = b; + this.c = c; + } + + @Override + public int compareTo(Node n) { + if(this.c > n.c){ + return 1; + }else if(this.c < n.c){ + return -1; + }else { + return 0; + } + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + + pq = new PriorityQueue<>(); + parent = new int[n+1]; + + for (int i = 0; i < n+1; i++) { + parent[i] =i; + } + + for (int i = 0; i < m; i++) { + st= new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + pq.add(new Node(a, b, c)); + } + + int cnt = n-1; + int ans = 0; + int lastWeight = 0; // 제일 마지막에 추가되는 간선의 가중치 + + while (cnt > 0){ + Node n = pq.poll(); + + if(union(n.a, n.b)){ + ans += n.c; + cnt--; + } + + if(cnt == 0) lastWeight = n.c; // 마지막 가중치 저장 + } + + // 마지막 가중치 제거 후 출력 + System.out.println(ans - lastWeight); + } + + private static boolean union(int a, int b){ + int root1 = find(a); + int root2 = find(b); + + if(root1 == root2) return false; + + if(root1 < root2){ + parent[root1] = root2; + }else{ + parent[root2] = root1; + } + return true; + } + + private static int find(int a){ + if(parent[a] == a){ + return a; + } + return find(parent[a]); + } +} \ No newline at end of file diff --git "a/seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" "b/seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" index e69de29..cc9087b 100644 --- "a/seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" +++ "b/seeun/week15/2166 \353\213\244\352\260\201\355\230\225 \353\251\264\354\240\201.java" @@ -0,0 +1,24 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + int[][] arr = new int[n+1][2]; + for (int i = 0; i < n; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + arr[i][0] = Integer.parseInt(st.nextToken()); + arr[i][1] = Integer.parseInt(st.nextToken()); + } + arr[n][0] = arr[0][0]; + arr[n][1] = arr[0][1]; + + long sum = 0; + for (int i = 0; i < n; i++) { + sum += (long)arr[i][0]*arr[i+1][1] - (long)arr[i+1][0]*arr[i][1]; + } + sum = Math.abs(sum); + System.out.printf("%.1f", (double)sum/2); + } +} \ No newline at end of file