From 3c2edaef75cc8a696db7b973eaf8c6a3c8d54e78 Mon Sep 17 00:00:00 2001 From: 0224LJH Date: Fri, 16 May 2025 09:45:16 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[Baekjoon-23291]=20=EC=96=B4=ED=95=AD=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\255\354\240\225\353\246\254.java" | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 "\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\226\264\355\225\255\354\240\225\353\246\254.java" diff --git "a/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\226\264\355\225\255\354\240\225\353\246\254.java" "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\226\264\355\225\255\354\240\225\353\246\254.java" new file mode 100644 index 0000000..d59d89f --- /dev/null +++ "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\226\264\355\225\255\354\240\225\353\246\254.java" @@ -0,0 +1,170 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class �������� { + + + static int size,tryCnt,goalDiff; + static int height,cnt,floor,stIdx; + static int[][] folded; + static int[][] temp; + static int[] arr; + static int[] dy = {-1,0,1,0}; + static int[] dx = {0,1,0,-1}; + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void print() {System.out.println(tryCnt);} + + private static void process() { + while(!isEnd()) { + tryCnt++; + plusSmallest(); + foldOne(); + foldHalf(); + } + } + + private static void plusSmallest() { + int smallest = Integer.MAX_VALUE; + ArrayList idxes = new ArrayList<>(); + for (int i = 0; i < size; i++) { + if (arr[i] == smallest) idxes.add(i); + else if (arr[i] < smallest) { + idxes.clear(); + smallest = arr[i]; + idxes.add(i); + } + } + for (int i = 0; i < idxes.size(); i++) { + arr[idxes.get(i)]++; + } + + } + + + private static void foldOne() { + folded = new int[size][size]; + height=1; //��� ����. ó������ ����1¥�� ����� �����Ѵٰ� ���� + floor=1; //�ٴ� ����. + cnt = 1; // ��� ���� + stIdx = 0; + + for (int i = 0; i < size; i++) folded[0][i] = arr[i]; + while(isValid()) { + int nIdx = stIdx+cnt; // ��� ���� �ٴ��� ù��° �ε��� + for (int j = 0; j < cnt; j++) { + for (int i = 0; i < height; i++) { + folded[cnt-j+floor-1][nIdx+i] = folded[i][j+stIdx]; + folded[i][j+stIdx] = 0; + } + } + stIdx = height*cnt; // ���� nIdx�� ù��° ����� ��ġ�� �� + if(height == cnt)height++; + else cnt++; + } + redistributeAll(); + } + + + private static boolean isValid() { + if (height == cnt) return size >= (height+1)*cnt; + return size >= height*(cnt+1); + } + + + private static void foldHalf() { + folded = new int[size][size]; + // 4��� ���� ��, ������ ��Ʈ�� �����ϴ� �ε��� + int[] pIdx = {0, size/4,(size/4)*2,(size/4)*3}; + int quater = size/4; + for (int i = 0; i < quater; i++) { + folded[0][pIdx[3]+i] = arr[pIdx[3]+i]; + folded[1][pIdx[3]+i] = arr[pIdx[1]-1-i]; + folded[2][pIdx[3]+i] = arr[pIdx[1]+i]; + folded[3][pIdx[3]+i] = arr[pIdx[3]-1-i]; + } + + redistributeAll(); + } + + + //��ü ��й� + private static void redistributeAll() { + temp = new int[size][size]; + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + redistribute(i,j); + } + } + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + // ��ȭ���� folded�� �ݿ� + folded[i][j] += temp[i][j]; + } + } + + sort(); + } + + private static void redistribute(int y, int x) { + for (int i = 0; i < 4; i++) { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if ( ny < 0 || nx <0 || ny >= size|| nx >= size)continue; + if (folded[ny][nx] == 0 || folded[y][x] <= folded[ny][nx])continue; + + //��й�� + int amount = (folded[y][x] - folded[ny][nx])/5; + temp[y][x] -= amount; + temp[ny][nx] += amount; + } + + } + + // �׿��ִ°��� �������. + private static void sort() { + int arrIdx = 0; + + for (int i = 0; i < size; i++) { + if (arrIdx == size) break; + if (folded[0][i] == 0) continue; + int idx = 0; + while(true) { + arr[arrIdx++] = folded[idx++][i]; + if(idx >= size || folded[idx][i] == 0) break; + } + } + } + + private static boolean isEnd() { + int largest = Integer.MIN_VALUE; + int smallest = Integer.MAX_VALUE; + for (int i = 0; i < size; i++) { + largest = Math.max(largest, arr[i]); + smallest = Math.min(smallest, arr[i]); + } + return largest-smallest <= goalDiff; + } + + private static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + size = Integer.parseInt(st.nextToken()); + goalDiff = Integer.parseInt(st.nextToken()); + tryCnt = 0; + arr = new int[size]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < size; i++) arr[i] = Integer.parseInt(st.nextToken()); + } +} From ebd9a9e023611c0cd7c172f8447305b5c2f99945 Mon Sep 17 00:00:00 2001 From: 0224LJH Date: Fri, 16 May 2025 09:47:31 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Baekjoon-1477]=20=ED=9C=B4=EA=B2=8C?= =?UTF-8?q?=EC=86=8C=20=EC=84=B8=EC=9A=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\204\270\354\232\260\352\270\260.java" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\355\234\264\352\262\214\354\206\214_\354\204\270\354\232\260\352\270\260.java" diff --git "a/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\355\234\264\352\262\214\354\206\214_\354\204\270\354\232\260\352\270\260.java" "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\355\234\264\352\262\214\354\206\214_\354\204\270\354\232\260\352\270\260.java" new file mode 100644 index 0000000..4c4aa22 --- /dev/null +++ "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\355\234\264\352\262\214\354\206\214_\354\204\270\354\232\260\352\270\260.java" @@ -0,0 +1,90 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collections; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class �ްԼ�_����� { + static PriorityQueue points = new PriorityQueue<>(); + static int[] distance; + static int pointCnt, plusCnt, len,ans,tempCnt; + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + pointCnt = Integer.parseInt(st.nextToken()); + plusCnt = Integer.parseInt(st.nextToken()); + len = Integer.parseInt(st.nextToken()); + distance = new int[pointCnt+1]; + ans = Integer.MAX_VALUE; + + points.add(0); + points.add(len); + + if (pointCnt != 0) { + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < pointCnt; i++) { + points.add(Integer.parseInt(st.nextToken())); + } + } + } + + private static void process() { + changeToDistance(); + findMinMax(); + } + + private static void changeToDistance() { + int pre = points.poll(); + + for (int i = 0; i <= pointCnt; i++) { + int cur = points.poll(); + distance[i] = cur - pre; + pre = cur; + + } + } + + private static void findMinMax() { + int l = 1; + int r = len+1; + int mid = (l+r)/2; + while(l < r) { + int cnt = getPlusCnt(mid); + if (cnt > plusCnt) { + // ��ǥ���� �� ���� ���� -> �������̰� �ʹ� ª��. �� �÷����� + l = mid+1; + } else if (cnt <= plusCnt) { + // ��ǥ���� �� ���� �������ų� ���� -> �������̸� �� �ٿ��� ��Ʈ���� + ans = Math.min(ans, mid); + r = mid; + } + mid = (l+r)/2; + } + } + + // �ִ��� num�϶� �߰��� �������ϴ� �ްԼ� ���� ��ȯ + private static int getPlusCnt(int num) { + tempCnt = 0; + for (int i = 0; i <= pointCnt; i++) { + if (distance[i] >= num) { + tempCnt += distance[i]/num; + if (distance[i]%num == 0) tempCnt--; + } + + } + //�������ϴ� �ްԼ� ������ ��ǥ���� ���ų� ������� + return tempCnt; + + } + + private static void print() {System.out.println(ans);} + +} From 83a5525eae2d0756f1affcd1e5153017a70225d3 Mon Sep 17 00:00:00 2001 From: 0224LJH Date: Fri, 16 May 2025 09:49:19 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[Baekjoon-2631]=20=EC=A4=84=20=EC=84=B8?= =?UTF-8?q?=EC=9A=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\204\270\354\232\260\352\270\260.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\244\204_\354\204\270\354\232\260\352\270\260.java" diff --git "a/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\244\204_\354\204\270\354\232\260\352\270\260.java" "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\244\204_\354\204\270\354\232\260\352\270\260.java" new file mode 100644 index 0000000..e081eb3 --- /dev/null +++ "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\244\204_\354\204\270\354\232\260\352\270\260.java" @@ -0,0 +1,30 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class ��_����� { + public static void main(String[] args) throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + //���� ���� ���� (LIS, Longest Increasing Subsequence) + int size = Integer.parseInt(br.readLine()); + int[] arr = new int[size]; + int[] dp = new int[size]; + for (int i = 0; i < size; i++) arr[i] = Integer.parseInt(br.readLine()); + + Arrays.fill(dp, 1); + for (int i = 1; i < size; i++) { + for (int j = 0; j Date: Fri, 16 May 2025 09:50:03 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Baekjoon-5582]=20=EA=B3=B5=ED=86=B5=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EB=AC=B8=EC=9E=90=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\254\270\354\236\220\354\227\264.java" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.java" diff --git "a/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.java" "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.java" new file mode 100644 index 0000000..5a69431 --- /dev/null +++ "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\352\263\265\355\206\265_\353\266\200\353\266\204_\353\254\270\354\236\220\354\227\264.java" @@ -0,0 +1,27 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class ����_�κ�_���ڿ� { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String[] input1 = br.readLine().split(""); + String[] input2 = br.readLine().split(""); + int[][] dp = new int[input1.length][input2.length]; + int ans = 0; + int temp = 0; + for (int i = 0; i < input1.length; i++) { + for (int j = 0; j < input2.length; j++) { + if(input1[i].equals(input2[j])) { + dp[i][j] = 1; + if(i == 0 || j == 0) continue; + + dp[i][j] += dp[i-1][j-1]; + ans = Math.max(ans, dp[i][j]); + } + } + } + System.out.println(ans); + } +} From fc90993ab3b833df7060d01becbceb6e4e8b41d0 Mon Sep 17 00:00:00 2001 From: 0224LJH Date: Fri, 16 May 2025 09:50:53 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[Baekjoon-2138]=20=EC=A0=84=EA=B5=AC?= =?UTF-8?q?=EC=99=80=20=EC=8A=A4=EC=9C=84=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\212\244\354\234\204\354\271\230.java" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.java" diff --git "a/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.java" "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.java" new file mode 100644 index 0000000..4e7bc2a --- /dev/null +++ "b/\354\235\264\354\242\205\355\231\230/17\354\243\274\354\260\250/\354\240\204\352\265\254\354\231\200_\354\212\244\354\234\204\354\271\230.java" @@ -0,0 +1,79 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class ������_����ġ { + static String[] input1,input2; + static int[] choice,flip; + static int len,ans; + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void print() {System.out.println((ans==Integer.MAX_VALUE)?-1:ans);} + + private static void process() { + getFlip(); + //������ġ ����ġ�� �ȴ����� ���� + choice[0] = 0; + greedy(); + //������ġ ����ġ�� ������ ���� + choice[0] = 1; + greedy(); + } + + + private static void getFlip() { + // �������� �Ǵ� �κ� ã�� + for (int i = 0; i < len; i++) flip[i] = !(input1[i].equals(input2[i]))?1:0; + + } + + private static void greedy() { + for (int i = 1; i < len; i++) { + int goal = flip[i-1]; // �̰� ��������� + int cur = (choice[i-1] + ((i > 1)?choice[i-2]:0))%2;// ���� �ΰ��������� ��Ȳ + choice[i] = Math.abs(goal-cur); + + } + + check(); + + } + + + private static void check() { + int temp = 0; + for (int i = 0; i < len; i++) { + temp += choice[i]; + int goal = flip[i]; + int cur = choice[i]; + + if (i > 0) cur += choice[i-1]; + if (i < len-1) cur += choice[i+1]; + cur %= 2; + + + if(goal != cur) return; + + } + + ans = Math.min(temp, ans); + + } + + private static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + len = Integer.parseInt(br.readLine()); + input1 = br.readLine().split(""); + input2 = br.readLine().split(""); + + choice = new int[len]; + flip = new int[len]; + ans = Integer.MAX_VALUE; + + } +}