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 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 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)); + + } + +} + +``` 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 "); + + } + +} + +``` 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"); + + } + +} + +``` 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; + } + + } + +} + +```