From 6e83cb6f6e9fddd3eb7256b4a79327cf227be1bb Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 2 Jun 2025 04:14:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[BOJ-1508]=20=EB=A0=88=EC=9D=B4=EC=8A=A4.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...] \353\240\210\354\235\264\354\212\244.md" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-1508] \353\240\210\354\235\264\354\212\244.md" diff --git "a/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-1508] \353\240\210\354\235\264\354\212\244.md" "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-1508] \353\240\210\354\235\264\354\212\244.md" new file mode 100644 index 0000000..334d435 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-1508] \353\240\210\354\235\264\354\212\244.md" @@ -0,0 +1,86 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N, M, K; + static int[] A; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + K = nextInt(); + A = new int[K]; + for(int i=0;i>1; + String answer = ""; + while(s>1; + } + bw.write(answer); + + } + + static String check(int dist) { + + for(int st=0;st<=K-M;st++){ + String res = "1"; + int last = A[st], cnt = 1; + for(int i=st+1;i Date: Mon, 2 Jun 2025 04:45:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[BOJ-14867]=20=EB=AC=BC=ED=86=B5.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[BOJ-14867] \353\254\274\355\206\265.md" | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-14867] \353\254\274\355\206\265.md" diff --git "a/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-14867] \353\254\274\355\206\265.md" "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-14867] \353\254\274\355\206\265.md" new file mode 100644 index 0000000..47e26c5 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-14867] \353\254\274\355\206\265.md" @@ -0,0 +1,130 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int A, B, EA, EB; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + A = nextInt(); + B = nextInt(); + EA = nextInt(); + EB = nextInt(); + + } + + static void solve() throws Exception { + + boolean[] emptyA = new boolean[B+1]; + boolean[] emptyB = new boolean[A+1]; + boolean[] fullA = new boolean[B+1]; + boolean[] fullB = new boolean[A+1]; + Queue Q = new LinkedList<>(); + + emptyA[0] = true; + emptyB[0] = true; + Q.offer(new int[]{0,0,0}); + while(!Q.isEmpty()){ + int[] now = Q.poll(); + int a = now[0], b = now[1], t = now[2]; + if(a == EA && b == EB){ + bw.write(t + "\n"); + return; + } + + if(a != A && !fullA[b] && (b != B || !fullB[A]) && (b != 0 || !emptyB[A])){ + fullA[b] = true; + if(b == B) fullB[A] = true; + if(b == 0) emptyB[A] = true; + Q.offer(new int[]{A,b,t+1}); + } + if(b != B && !fullB[a] && (a != A || !fullA[B]) && (a != 0 || !emptyA[B])){ + fullB[a] = true; + if(a == A) fullA[B] = true; + if(a == 0) emptyA[B] = true; + Q.offer(new int[]{a,B,t+1}); + } + if(a != 0 && !emptyA[b] && (b != B || !fullB[0]) && (b != 0 || !emptyB[0])){ + emptyA[b] = true; + if(b == B) fullB[0] = true; + if(b == 0) emptyB[0] = true; + Q.offer(new int[]{0,b,t+1}); + } + if(b != 0 && !emptyB[a] && (a != A || !fullA[0]) && (a != 0 || !emptyA[0])){ + emptyB[a] = true; + if(a == A) fullA[0] = true; + if(a == 0) emptyA[0] = true; + Q.offer(new int[]{a,0,t+1}); + } + + if(a != 0) { + int diff = Math.min(a, B-b); + int na = a-diff, nb = b+diff; + if(na == 0){ + if(!emptyA[nb] && (nb != B || !fullB[0])){ + emptyA[nb] = true; + if(nb == B) fullB[0] = true; + Q.offer(new int[]{na,nb,t+1}); + } + } + else{ + if(!fullB[na]){ + fullB[na] = true; + Q.offer(new int[]{na,nb,t+1}); + } + } + } + if(b != 0) { + int diff = Math.min(b, A-a); + int na = a+diff, nb = b-diff; + if(nb == 0){ + if(!emptyB[na] && (na != A || !fullA[0])){ + emptyB[na] = true; + if(na == A) fullA[0] = true; + Q.offer(new int[]{na,nb,t+1}); + } + } + else{ + if(!fullA[nb]){ + fullA[nb] = true; + Q.offer(new int[]{na,nb,t+1}); + } + } + } + } + bw.write("-1"); + + } + + + +} +``` From 5abbccccdf11513067858d38284e2fda1f4f1de7 Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 2 Jun 2025 06:14:09 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[BOJ-9177]=20=EB=8B=A8=EC=96=B4=20=EC=84=9E?= =?UTF-8?q?=EA=B8=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\226\264 \354\204\236\352\270\260.md" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-9177] \353\213\250\354\226\264 \354\204\236\352\270\260.md" diff --git "a/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-9177] \353\213\250\354\226\264 \354\204\236\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-9177] \353\213\250\354\226\264 \354\204\236\352\270\260.md" new file mode 100644 index 0000000..2863c6c --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-9177] \353\213\250\354\226\264 \354\204\236\352\270\260.md" @@ -0,0 +1,65 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static char[] A, B, C; + + public static void main(String[] args) throws Exception { + + int T = nextInt(); + for(int i=1;i<=T;solve(i++)) ready(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + A = ("?" + nextToken()).toCharArray(); + B = ("?" + nextToken()).toCharArray(); + C = ("?" + nextToken()).toCharArray(); + + } + + static void solve(int tc) throws Exception { + + bw.write("Data set " + tc + ": "); + int N = A.length-1, M = B.length-1; + boolean[][] dp = new boolean[N+1][M+1]; + dp[0][0] = true; + for(int i=1;i<=N+M;i++){ + boolean res = false; + for(int j=0;j<=Math.min(i,N);j++) if(i-j <= M) { + dp[j][i-j] = (A[j] == C[i] && dp[j-1][i-j]) || (B[i-j] == C[i] && dp[j][i-j-1]); + res |= dp[j][i-j]; + } + if(!res) { + bw.write("no\n"); + return; + } + } + bw.write("yes\n"); + + } + +} +``` From 602c1a5ae13858cfb170d2eab3ab7e8331d5f17e Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 2 Jun 2025 06:25:02 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[BOJ-2696]=20=EC=A4=91=EC=95=99=EA=B0=92=20?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EA=B8=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 \352\265\254\355\225\230\352\270\260.md" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-2696] \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" diff --git "a/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-2696] \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-2696] \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" new file mode 100644 index 0000000..2b52f69 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-2696] \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" @@ -0,0 +1,64 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N; + static PriorityQueue low, high; + + public static void main(String[] args) throws Exception { + + int T = nextInt(); + for(int i=1;i<=T;solve(i++)) ready(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + low = new PriorityQueue<>((a,b) -> b-a); + high = new PriorityQueue<>((a,b) -> a-b); + + } + + static void solve(int tc) throws Exception { + + bw.write((N+1)/2 + "\n"); + for(int i=1;i<=N;i++){ + int a = nextInt(); + if(i%2 == 1) low.add(a); + else high.add(a); + if(!high.isEmpty() && low.peek() > high.peek()){ + int l = low.poll(), h = high.poll(); + low.add(h); + high.add(l); + } + if(i%2 == 1) bw.write(low.peek() + " "); + if(i%20 == 19) bw.write("\n"); + } + bw.write("\n"); + + } + +} +``` From 02b854e6c64e5d43cbb5f9d58d28e33ac81c8594 Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 2 Jun 2025 06:49:44 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[BOJ-3108]=20=EB=A1=9C=EA=B3=A0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[BOJ-3108] \353\241\234\352\263\240.md" | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-3108] \353\241\234\352\263\240.md" diff --git "a/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-3108] \353\241\234\352\263\240.md" "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-3108] \353\241\234\352\263\240.md" new file mode 100644 index 0000000..0c699a5 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_19\354\243\274\354\260\250/[BOJ-3108] \353\241\234\352\263\240.md" @@ -0,0 +1,93 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N; + static int[] r; + + static int f(int x) {return x==r[x] ? x : (r[x]=f(r[x]));} + static int comp(int x, int y) {return x*1001 + y;} + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + r = new int[1001*1001]; + for(int i=0;i<1001*1001;i++) r[i] = i; + + } + + static void solve() throws Exception { + + List L = new ArrayList<>(); + L.add(comp(500,500)); + for(int i=0;i S = new TreeSet<>(); + for(int i:L) S.add(f(i)); + bw.write((S.size()-1) + "\n"); + + } + +} +```