From 7b57fcbc1817f4aa6a7e2cd43d98722176b6093a Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 11 Apr 2025 10:33:56 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[BOJ-7682]=20=ED=8B=B1=ED=83=9D=ED=86=A0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...] \355\213\261\355\203\235\355\206\240.md" | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-7682] \355\213\261\355\203\235\355\206\240.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-7682] \355\213\261\355\203\235\355\206\240.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-7682] \355\213\261\355\203\235\355\206\240.md" new file mode 100644 index 00000000..890d133b --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-7682] \355\213\261\355\203\235\355\206\240.md" @@ -0,0 +1,135 @@ +```java + +import java.util.*; +import java.io.*; + +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[][] T; + static String temp; + + public static void main(String[] args) throws Exception { + + for(temp = br.readLine();!temp.equals("end");temp = br.readLine()) { + + ready(); + solve(); + } + + bwEnd(); + + } + + static void ready() throws Exception{ + + T = new char[3][3]; + for(int i=0;i<9;i++) T[i/3][i%3] = temp.charAt(i); + + } + + static void solve() throws Exception{ + + // X의 개수 - O의 개수 확인 + int xCount = 0, oCount = 0; + for(int i=0;i<3;i++) for(int j=0;j<3;j++) { + xCount += T[i][j] == 'X' ? 1 : 0; + oCount += T[i][j] == 'O' ? 1 : 0; + } + if(xCount - oCount < 0 || xCount - oCount > 1) { + bw.write("invalid\n"); + return; + } + + // 대각선 승리 + int xDiagWin = 0, oDiagWin = 0; + if(T[0][0] == 'X' && T[1][1] == 'X' && T[2][2] == 'X') xDiagWin++; + if(T[0][0] == 'O' && T[1][1] == 'O' && T[2][2] == 'O') oDiagWin++; + if(T[0][2] == 'X' && T[1][1] == 'X' && T[2][0] == 'X') xDiagWin++; + if(T[0][2] == 'O' && T[1][1] == 'O' && T[2][0] == 'O') oDiagWin++; + if(xDiagWin > 0) { + if(xCount == oCount) { + bw.write("invalid\n"); + return; + } + bw.write("valid\n"); + return; + } + else if(oDiagWin > 0) { + if(xCount > oCount) { + bw.write("invalid\n"); + return; + } + bw.write("valid\n"); + return; + } + + // 성공 패턴의 개수 + int xWin = 0, oWin = 0; + for(int i=0;i<3;i++) { + int res = 0; + for(int j=0;j<3;j++) res += T[i][j] == 'X' ? 1 : 0; + if(res == 3) xWin++; + res = 0; + for(int j=0;j<3;j++) res += T[i][j] == 'O' ? 1 : 0; + if(res == 3) oWin++; + } + for(int j=0;j<3;j++) { + int res = 0; + for(int i=0;i<3;i++) res += T[i][j] == 'X' ? 1 : 0; + if(res == 3) xWin++; + res = 0; + for(int i=0;i<3;i++) res += T[i][j] == 'O' ? 1 : 0; + if(res == 3) oWin++; + } + if(xWin + oWin == 0) { + if(xCount + oCount != 9) { + bw.write("invalid\n"); + return; + } + bw.write("valid\n"); + return; + } + if(xWin>0 && oWin>0) { + bw.write("invalid\n"); + return; + } + + if(xWin > 0) { + if(xCount == oCount) { + bw.write("invalid\n"); + return; + } + bw.write("valid\n"); + return; + } + else { + if(xCount > oCount) { + bw.write("invalid\n"); + return; + } + bw.write("valid\n"); + return; + } + + } + +} + +``` From ec910c4a016553ca542535bf8eb90bfb04d36b35 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 15 Apr 2025 11:40:10 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[BOJ-1405]=20=EB=AF=B8=EC=B9=9C=20=EB=A1=9C?= =?UTF-8?q?=EB=B4=87.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\271\234 \353\241\234\353\264\207.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1405] \353\257\270\354\271\234 \353\241\234\353\264\207.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1405] \353\257\270\354\271\234 \353\241\234\353\264\207.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1405] \353\257\270\354\271\234 \353\241\234\353\264\207.md" new file mode 100644 index 00000000..162db478 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1405] \353\257\270\354\271\234 \353\241\234\353\264\207.md" @@ -0,0 +1,38 @@ +```python + +K, E, W, N, S = map(int, input().split()) + +vis = [[0 for _ in range(30)] for _ in range(30)] +cnt = 0 +dp = [E,W,N,S] +dx = [1,-1,0,0] +dy = [0,0,1,-1] + +def dfs(x, y, c, p): + global vis + global cnt + global dp + global dx + global dy + if c == K: + cnt += p + return + for i in range(4): + xx, yy = x+dx[i], y+dy[i] + if vis[xx][yy] != 0: + continue + vis[xx][yy]+=1 + dfs(xx,yy,c+1,p*dp[i]) + vis[xx][yy]-=1 + + +vis[15][15]+=1 +for i in range(4): + x, y = 15+dx[i], 15+dy[i] + vis[x][y]+=1 + dfs(x,y,1,dp[i]) + vis[x][y]-=1 + +print(cnt / (100**K)) + +``` From d986f96bf58f49b55e58aad80ffef0dbda237f05 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 15 Apr 2025 11:40:30 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[BOJ-3079]=20=EC=9E=85=EA=B5=AD=EC=8B=AC?= =?UTF-8?q?=EC=82=AC.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...05\352\265\255\354\213\254\354\202\254.md" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-3079] \354\236\205\352\265\255\354\213\254\354\202\254.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-3079] \354\236\205\352\265\255\354\213\254\354\202\254.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-3079] \354\236\205\352\265\255\354\213\254\354\202\254.md" new file mode 100644 index 00000000..a015f78a --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-3079] \354\236\205\352\265\255\354\213\254\354\202\254.md" @@ -0,0 +1,66 @@ +```java + +import java.util.*; +import java.io.*; + +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 long N, M; + static long[] T; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + T = new long[(int)N]; + for(int i=0;i>1; + while(s= M) poss = true; + } + if(poss) e = m; + else s = m+1; + m = (s+e)>>1; + } + bw.write(m + "\n"); + + } + +} + +``` From 8c63689e753d168290ff654be6cbafec3521b861 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 15 Apr 2025 11:58:40 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[BOJ-21278]=20=ED=98=B8=EC=84=9D=EC=9D=B4?= =?UTF-8?q?=20=EB=91=90=20=EB=A7=88=EB=A6=AC=20=EC=B9=98=ED=82=A8.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\246\254 \354\271\230\355\202\250.md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-21278] \355\230\270\354\204\235\354\235\264 \353\221\220 \353\247\210\353\246\254 \354\271\230\355\202\250.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-21278] \355\230\270\354\204\235\354\235\264 \353\221\220 \353\247\210\353\246\254 \354\271\230\355\202\250.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-21278] \355\230\270\354\204\235\354\235\264 \353\221\220 \353\247\210\353\246\254 \354\271\230\355\202\250.md" new file mode 100644 index 00000000..9ed24388 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-21278] \355\230\270\354\204\235\354\235\264 \353\221\220 \353\247\210\353\246\254 \354\271\230\355\202\250.md" @@ -0,0 +1,88 @@ +```java + +import java.util.*; +import java.io.*; + +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; + static boolean[][] V; + static int[][] dist; + + static final int INF = (int)1e9 + 7; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + dist = new int[N+1][N+1]; + V = new boolean[N+1][N+1]; + for(int i=0;i Q = new LinkedList<>(); + boolean[] vis = new boolean[N+1]; + Q.offer(new int[] {i,0}); + vis[i] = true; + while(!Q.isEmpty()) { + int[] now = Q.poll(); + int n = now[0], t = now[1]; + dist[i][n] = t; + for(int j=1;j<=N;j++) if(V[n][j] && !vis[j]) { + vis[j] = true; + Q.offer(new int[] {j,t+1}); + } + } + } + + int ans = INF, A = -1, B = -1; + for(int i=1;i<=N;i++) for(int j=i+1;j<=N;j++) { + int res = 0; + for(int k=1;k<=N;k++) res += Math.min(dist[k][i], dist[k][j]); + if(res < ans) { + ans = res; + A = i; + B = j; + } + } + bw.write(A + " " + B + " " + (ans*2)); + + } + +} + +``` From 08787c77932355249584c360df3bfa6016b843bc Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 15 Apr 2025 12:04:22 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[BOJ-2629]=20=EC=96=91=ED=8C=94=EC=A0=80?= =?UTF-8?q?=EC=9A=B8.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...21\355\214\224\354\240\200\354\232\270.md" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-2629] \354\226\221\355\214\224\354\240\200\354\232\270.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-2629] \354\226\221\355\214\224\354\240\200\354\232\270.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-2629] \354\226\221\355\214\224\354\240\200\354\232\270.md" new file mode 100644 index 00000000..249f0920 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-2629] \354\226\221\355\214\224\354\240\200\354\232\270.md" @@ -0,0 +1,63 @@ +```java + +import java.util.*; +import java.io.*; + +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; + static TreeSet S = new TreeSet<>(); + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + + } + + static void solve() throws Exception{ + + S.add(0); + for(int i=0;i NS = new TreeSet<>(); + for(int s:S) { + NS.add(s+a); + NS.add(Math.abs(s-a)); + } + for(int ns:NS) S.add(ns); + NS.clear(); + } + + for(M = nextInt();M-->0;) bw.write(S.contains(nextInt()) ? "Y " : "N "); + + } + +} + +``` From 2e213e111d7aef0d52d8c32bb9ebe8ce2d3feb63 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 15 Apr 2025 12:20:45 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[BOJ-1327]=20=EC=86=8C=ED=8A=B8=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\212\270 \352\262\214\354\236\204.md" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1327] \354\206\214\355\212\270 \352\262\214\354\236\204.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1327] \354\206\214\355\212\270 \352\262\214\354\236\204.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1327] \354\206\214\355\212\270 \352\262\214\354\236\204.md" new file mode 100644 index 00000000..8d3db2a8 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-1327] \354\206\214\355\212\270 \352\262\214\354\236\204.md" @@ -0,0 +1,101 @@ +```java + +import java.util.*; +import java.io.*; + +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 class Node{ + String per; + int time; + Node(String per, int time){ + this.per = per; + this.time = time; + } + } + + static int N, K; + static int[] A; + static TreeSet T = new TreeSet<>(); + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + K = nextInt(); + A = new int[N]; + for(int i=0;i Q = new LinkedList<>(); + Q.offer(new Node(tostr(A), 0)); + while(!Q.isEmpty()) { + Node now = Q.poll(); + String cur = now.per; + int t = now.time; + if(cur.equals(endstr)) { + bw.write(t + "\n"); + return; + } + + int[] arr = new int[N]; + for(int i=0;i Date: Tue, 15 Apr 2025 14:04:44 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[BOJ-11049]=20=ED=96=89=EB=A0=AC=20?= =?UTF-8?q?=EA=B3=B1=EC=85=88=20=EC=88=9C=EC=84=9C.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\205\210 \354\210\234\354\204\234.md" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-11049] \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" diff --git "a/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-11049] \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-11049] \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" new file mode 100644 index 00000000..8c07c007 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_12\354\243\274\354\260\250/[BOJ-11049] \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" @@ -0,0 +1,63 @@ +```java + +import java.util.*; +import java.io.*; + +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[][] dp; + static int[][] A; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + A = new int[N][2]; + for(int i=0;i