diff --git "a/\354\235\264\354\230\210\354\235\200/Week26_0919/B_20058.java" "b/\354\235\264\354\230\210\354\235\200/Week26_0919/B_20058.java" new file mode 100644 index 0000000..f5f6a77 --- /dev/null +++ "b/\354\235\264\354\230\210\354\235\200/Week26_0919/B_20058.java" @@ -0,0 +1,118 @@ +package BaekJoon; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class B_20058 { + static final int r[] = {-1, 0, 1, 0}, c[] = {0,1,0,-1}; + static int N, Q, L, sum, A[][]; + static Queue queue; + static boolean visit[][]; + + static void divide() { + for(int i=0; i= N || dc < 0 || dc >= N || A[dr][dc] < 1) cnt++; + } + + if(cnt > 1) queue.add(new int[] {i, j}); + } + } + + while(!queue.isEmpty()) { + int ice[] = queue.poll(); + A[ice[0]][ice[1]]--; + } + } + + static int getIce(int x, int y) { + int cnt = 0; + queue.add(new int[] {x, y, A[x][y]}); + visit[x][y] = true; + + while(!queue.isEmpty()) { + int ice[] = queue.poll(); + cnt++; + sum += ice[2]; + + for(int d=0; d<4; d++) { + int dr = ice[0] + r[d]; + int dc = ice[1] + c[d]; + + if(dr < 0 || dr >= N || dc < 0 || dc >= N || visit[dr][dc] || A[dr][dc] < 1) continue; + + visit[dr][dc] = true; + queue.add(new int[]{dr, dc, A[dr][dc]}); + } + } + + return cnt; + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = (int)Math.pow(2, Integer.parseInt(st.nextToken())); + Q = Integer.parseInt(st.nextToken()); + A = new int[N][N]; + queue = new LinkedList(); + visit = new boolean[N][N]; + sum = 0; + int cnt = 0; + + for(int i=0; i 0) cnt = Math.max(cnt, getIce(i, j)); + } + } + + System.out.println(sum+"\n"+cnt); + } +} \ No newline at end of file diff --git "a/\354\235\264\354\230\210\354\235\200/Week26_0919/B_2310.java" "b/\354\235\264\354\230\210\354\235\200/Week26_0919/B_2310.java" new file mode 100644 index 0000000..cec5a18 --- /dev/null +++ "b/\354\235\264\354\230\210\354\235\200/Week26_0919/B_2310.java" @@ -0,0 +1,62 @@ +package BaekJoon; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class B_2310 { + static int N, money[], cost[]; + static ArrayList room[]; + + static boolean move(int n, int sum) { + if(n == N-1) return true; + + for(int idx : room[n]) { + int next = sum; + + if(money[idx] < 0) next += money[idx]; + else if(next < money[idx]) next = money[idx]; + + if(cost[idx] < next) { + cost[idx] = next; + if(move(idx, next)) return true; + } + } + + return false; + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + while(true) { + N = Integer.parseInt(br.readLine()); + if(N == 0) break; + money = new int[N]; + cost = new int[N]; + room = new ArrayList[N]; + Arrays.fill(cost, -1); + + for(int i=0; i(); + + if(st.nextToken().equals("T")) money[i] = -Integer.parseInt(st.nextToken()); + else money[i] = Integer.parseInt(st.nextToken()); + + while(true) { + int n = Integer.parseInt(st.nextToken()); + if(n == 0) break; + room[i].add(n-1); + } + } + + sb.append(money[0] >= 0 && move(0, money[0]) ? "Yes\n" : "No\n"); + } + + System.out.print(sb); + } +} \ No newline at end of file diff --git "a/\354\235\264\354\230\210\354\235\200/Week26_0919/B_27497.java" "b/\354\235\264\354\230\210\354\235\200/Week26_0919/B_27497.java" new file mode 100644 index 0000000..483a0cf --- /dev/null +++ "b/\354\235\264\354\230\210\354\235\200/Week26_0919/B_27497.java" @@ -0,0 +1,41 @@ +package BaekJoon; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.Stack; +import java.util.StringTokenizer; + +public class B_27497 { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + Deque deque = new ArrayDeque(); + Stack stack = new Stack(); + StringBuilder sb = new StringBuilder(); + + while(N-- > 0) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int button = Integer.parseInt(st.nextToken()); + + if(button == 3) { + if(!stack.isEmpty()) { + if(stack.pop() == 1) deque.pollLast(); + else deque.pollFirst(); + } + } else { + stack.push(button); + if(button == 1) deque.addLast(st.nextToken().charAt(0)); + else deque.addFirst(st.nextToken().charAt(0)); + } + } + + while(!deque.isEmpty()) { + sb.append(deque.poll()); + } + + System.out.print(sb.length() == 0 ? 0 : sb); + } +} \ No newline at end of file