diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-13397] \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-13397] \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.md" new file mode 100644 index 00000000..647a5e3a --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-13397] \352\265\254\352\260\204 \353\202\230\353\210\204\352\270\260 2.md" @@ -0,0 +1,73 @@ +```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; + static int[] A; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception { + + N = nextInt(); + M = nextInt(); + A = new int[N]; + for(int i=0;i k) { + cnt++; + min = A[i]; + max = A[i]; + } + else { + min = tmin; + max = tmax; + } + } + if(cnt <= M) { + bw.write(k + "\n"); + return; + } + } + + } + +} + +``` diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-1451] \354\247\201\354\202\254\352\260\201\355\230\225\354\234\274\353\241\234 \353\202\230\353\210\204\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-1451] \354\247\201\354\202\254\352\260\201\355\230\225\354\234\274\353\241\234 \353\202\230\353\210\204\352\270\260.md" new file mode 100644 index 00000000..38edefe5 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-1451] \354\247\201\354\202\254\352\260\201\355\230\225\354\234\274\353\241\234 \353\202\230\353\210\204\352\270\260.md" @@ -0,0 +1,50 @@ +```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 + + + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + + + } + + static void solve() throws Exception{ + + + + } + +} + +``` diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-1509] \355\214\260\353\246\260\353\223\234\353\241\254 \353\266\204\355\225\240.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-1509] \355\214\260\353\246\260\353\223\234\353\241\254 \353\266\204\355\225\240.md" new file mode 100644 index 00000000..c944e055 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-1509] \355\214\260\353\246\260\353\223\234\353\241\254 \353\266\204\355\225\240.md" @@ -0,0 +1,81 @@ +```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 char[] A; + static boolean[][] isPalindrome; + static int[] dp; + static final int INF = 123456; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + A = br.readLine().toCharArray(); + N = A.length; + isPalindrome = new boolean[N][N]; + + } + + static void solve() throws Exception{ + + for(int i=0;i=0 && i+k=0 && i+1+k E; + static int idx = 1; + static int[] r; + + static int[] dx = {1,0,-1,0}; + static int[] dy = {0,1,0,-1}; + + static int f(int x) {return x==r[x] ? x : (r[x]=f(r[x]));} + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + A = new int[N][N]; + info = new int[M+1][]; + for(int i=0;i(); + r = new int[M+1]; + for(int i=0;i<=M;i++) r[i] = i; + + } + + static void solve() throws Exception{ + + for(int i=0;i<=M;i++) { + Queue Q = new LinkedList<>(); + boolean[][] vis = new boolean[N][N]; + vis[info[i][0]][info[i][1]] = true; + Q.offer(new int[] {info[i][0], info[i][1], 0}); + while(!Q.isEmpty()) { + int[] now = Q.poll(); + int x = now[0], y = now[1], t = now[2]; + if(A[x][y] >= 0 && A[x][y] != i) E.add(new int[] {i,A[x][y],t}); + for(int k=0;k<4;k++) { + int xx = x+dx[k], yy = y+dy[k]; + if(xx<0 || xx>=N || yy<0 || yy>=N || vis[xx][yy] || A[xx][yy] == -2) continue; + vis[xx][yy] = true; + Q.offer(new int[] {xx,yy,t+1}); + } + } + } + + Collections.sort(E, (a,b) -> a[2]-b[2]); + + int cnt = 0, mst = 0; + for(int[] e : E) { + int a = e[0], b = e[1], c = e[2]; + int x = f(a), y = f(b); + if(x == y) continue; + cnt++; + mst += c; + r[x] = y; + } + + bw.write((cnt == M ? mst : -1) + "\n"); + + } + +} + +``` diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-20055] \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-20055] \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" new file mode 100644 index 00000000..85962764 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-20055] \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" @@ -0,0 +1,101 @@ +```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, K; + static int[] A; + static List R; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + K = nextInt(); + A = new int[N*2]; + R = new ArrayList<>(); + for(int i=0;i0;i--) A[i] = A[i-1]; + A[0] = last; + + boolean[] ex = new boolean[N+1]; + List NR = new ArrayList<>(); + for(int i:R) if(i != N-2) { + NR.add(i+1); + ex[i+1] = true; + } + R = NR; + + // step 2 + List NNR = new ArrayList<>(); + for(int i:R) { + if(!ex[i+1] && A[i+1] >= 1) { + A[i+1]--; + ex[i] = false; + if(i+1 != N-1) { + NNR.add(i+1); + ex[i+1] = true; + } + } + else NNR.add(i); + } + R = NNR; + + // step 3 + if(A[0] != 0) { + A[0]--; + R.add(0); + } + + // step 4 + int cnt = 0; + for(int i=0;i= K) break; + + turn++; + + } + bw.write(turn + "\n"); + + } + +} + +``` diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-2307] \353\217\204\353\241\234\352\262\200\353\254\270.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-2307] \353\217\204\353\241\234\352\262\200\353\254\270.md" new file mode 100644 index 00000000..7ca5c582 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-2307] \353\217\204\353\241\234\352\262\200\353\254\270.md" @@ -0,0 +1,120 @@ +```java + +import java.util.*; +import java.io.*; + +class Node{ + int next, cost; + Node(int next, int cost){ + this.next = next; + this.cost = cost; + } +} + +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 List[] V; + static int[][] E; + static final int INF = (int)1e9; + static PriorityQueue Q = new PriorityQueue<>((a,b) -> a[0]-b[0]); + static int[] D; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + V = new List[N+1]; + D = new int[N+1]; + for(int i=1;i<=N;i++) V[i] = new ArrayList<>(); + E = new int[M][3]; + for(int i=0;i D[n]) continue; + if(n == N) return d; + for(Node x:V[n]){ + int i = x.next, c = x.cost; + if(D[i] > d+c){ + D[i] = d+c; + Q.offer(new int[]{D[i],i}); + } + } + } + return -1; + } + +} + +``` diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-2479] \352\262\275\353\241\234 \354\260\276\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-2479] \352\262\275\353\241\234 \354\260\276\352\270\260.md" new file mode 100644 index 00000000..6ffbac6d --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-2479] \352\262\275\353\241\234 \354\260\276\352\270\260.md" @@ -0,0 +1,92 @@ +```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, K, S, E; + static int[] A; + static boolean[][] edge; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + K = nextInt(); + A = new int[N+1]; + edge = new boolean[N+1][N+1]; + for(int i=1;i<=N;i++) { + char[] temp = br.readLine().toCharArray(); + for(int j=0;j Q = new LinkedList<>(); + int[] par = new int[N+1]; + Q.offer(S); + par[S] = -1; + while(!Q.isEmpty()) { + int n = Q.poll(); + if(n == E) { + Stack S = new Stack<>(); + while(n != -1) { + S.add(n); + n = par[n]; + } + while(!S.isEmpty()) bw.write(S.pop() + " "); + return; + } + + for(int i=1;i<=N;i++) if(edge[n][i] && par[i] == 0) { + par[i] = n; + Q.offer(i); + } + } + bw.write("-1"); + + } + +} + +``` diff --git "a/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-7662] \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-7662] \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" new file mode 100644 index 00000000..8f23c0ce --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_11\354\243\274\354\260\250/[BOJ-7662] \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" @@ -0,0 +1,71 @@ +```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 K; + static TreeMap T; + + public static void main(String[] args) throws Exception { + + for(int TC=nextInt();TC-->0;) { + + ready(); + solve(); + } + + bwEnd(); + + } + + static void ready() throws Exception{ + + K = nextInt(); + T = new TreeMap<>(); + + } + + static void solve() throws Exception{ + + while(K-->0) { + char op = nextToken().charAt(0); + int x = nextInt(); + if(op == 'D') { + if(T.isEmpty()) continue; + int k = x==1 ? T.lastKey() : T.firstKey(); + T.replace(k, T.get(k)-1); + if(T.get(k) == 0) T.remove(k); + } + else { + if(!T.containsKey(x)) T.put(x, 0); + T.replace(x, T.get(x)+1); + } + } + + if(T.isEmpty()) bw.write("EMPTY\n"); + else bw.write(T.lastKey() + " " + T.firstKey() + "\n"); + + } + +} + +```