diff --git "a/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-2169] \353\241\234\353\264\207 \354\241\260\354\242\205\355\225\230\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-2169] \353\241\234\353\264\207 \354\241\260\354\242\205\355\225\230\352\270\260.md" new file mode 100644 index 00000000..70bccee8 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-2169] \353\241\234\353\264\207 \354\241\260\354\242\205\355\225\230\352\270\260.md" @@ -0,0 +1,66 @@ +```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, dp, left, right; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + A = new int[N+2][M+2]; + for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) A[i][j] = nextInt(); + dp = new int[N+2][M+2]; + Arrays.fill(dp[0], -(int)1e9); + left = new int[N+2][M+2]; + right = new int[N+2][M+2]; + right[1][M+1] = -(int)1e9; + for(int i=2;i<=N;i++){ + left[i][0] = -(int)1e9; + right[i][M+1] = -(int)1e9; + } + + } + + static void solve() throws Exception { + + for(int i=1;i<=N;i++) { + for(int j=1;j<=M;j++) left[i][j] = Math.max(left[i][j-1], dp[i-1][j]) + A[i][j]; + for(int j=M;j>=1;j--) right[i][j] = Math.max(right[i][j+1], dp[i-1][j]) + A[i][j]; + for(int j=1;j<=M;j++) dp[i][j] = Math.max(left[i][j], right[i][j]); + } + bw.write(dp[N][M] + "\n"); + + } + +} +``` diff --git "a/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-2461] \353\214\200\355\221\234 \354\204\240\354\210\230.md" "b/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-2461] \353\214\200\355\221\234 \354\204\240\354\210\230.md" new file mode 100644 index 00000000..33e9e234 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-2461] \353\214\200\355\221\234 \354\204\240\354\210\230.md" @@ -0,0 +1,88 @@ +```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 class Node{ + int cur, nxt, row, col; + Node(int cur, int nxt, int row, int col){ + this.cur = cur; + this.nxt = nxt; + this.row = row; + this.col = col; + } + } + + 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][M]; + for(int i=0;i Q = new PriorityQueue<>((a,b) -> { + if(a.cur == b.cur){ + if(a.nxt == -1) return 1; + if(b.nxt == -1) return -1; + return a.nxt - b.nxt; + } + return a.cur - b.cur; + }); + + int e = -1; + for(int i=0;i[] V, C; + + public static void main(String[] args) throws Exception { + + int T = nextInt(); + for(int t=1;t<=T;solve(t++)) ready(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + K = nextInt(); + M = nextInt(); + P = nextInt(); + V = new List[M+1]; + C = new List[M+1]; + for(int i=1;i<=M;i++) { + V[i] = new ArrayList<>(); + C[i] = new ArrayList<>(); + } + d = new int[M+1]; + for(int i=0;i Q = new LinkedList<>(); + for(int i=1;i<=M;i++) if(d[i] == 0) { + Q.offer(i); + C[i].add(1); + } + + while(!Q.isEmpty()) { + int n = Q.poll(); + Collections.sort(C[n], (a,b) -> b-a); + int c = C[n].get(0); + if(C[n].size() > 1 && C[n].get(0).equals(C[n].get(1))) c++; + if(n == M){ + bw.write(tc + " " + c + "\n"); + return; + } + for(int i:V[n]) { + if(--d[i] == 0) Q.offer(i); + C[i].add(c); + } + } + + } + +} +``` diff --git "a/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-9576] \354\261\205 \353\202\230\353\210\240\354\243\274\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-9576] \354\261\205 \353\202\230\353\210\240\354\243\274\352\270\260.md" new file mode 100644 index 00000000..319bb928 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_18\354\243\274\354\260\250/[BOJ-9576] \354\261\205 \353\202\230\353\210\240\354\243\274\352\270\260.md" @@ -0,0 +1,68 @@ +```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; + static boolean[] received; + + public static void main(String[] args) throws Exception { + + for(int T=nextInt();T-->0;solve()) ready(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + A = new int[M][2]; + received = new boolean[M]; + for(int i=0;i= i) { + if(A[j][1] < emin){ + emin = A[j][1]; + idx = j; + } + } + if(idx != -1) { + received[idx] = true; + cnt++; + } + + } + bw.write(cnt + "\n"); + + } + +} +```