Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions 권혁준_18주차/[BOJ-2169] 로봇 조종하기.md
Original file line number Diff line number Diff line change
@@ -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");

}

}
```
88 changes: 88 additions & 0 deletions 권혁준_18주차/[BOJ-2461] 대표 선수.md
Original file line number Diff line number Diff line change
@@ -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<N;i++){
for(int j=0;j<M;j++) A[i][j] = nextInt();
Arrays.sort(A[i]);
}

}

static void solve() throws Exception {

PriorityQueue<Node> 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<N;i++) {
Q.offer(new Node(A[i][0], 1<M ? A[i][1] : -1, i, 1));
e = Math.max(e, A[i][0]);
}
int ans = e-Q.peek().cur;
while(Q.peek().nxt != -1){
Node now = Q.poll();
e = Math.max(e, now.nxt);
Q.offer(new Node(now.nxt, now.col+1 < M ? A[now.row][now.col+1] : -1, now.row, now.col+1));
ans = Math.min(ans, e-Q.peek().cur);
}
bw.write(ans + "\n");



}

}
```
83 changes: 83 additions & 0 deletions 권혁준_18주차/[BOJ-9470] Strahler 순서.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
```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, M, P;
static int[] d;
static List<Integer>[] 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<P;i++) {
int a = nextInt(), b = nextInt();
V[a].add(b);
d[b]++;
}

}

static void solve(int tc) throws Exception {

Queue<Integer> 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);
}
}

}

}
```
68 changes: 68 additions & 0 deletions 권혁준_18주차/[BOJ-9576] 책 나눠주기.md
Original file line number Diff line number Diff line change
@@ -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<M;i++) for(int j=0;j<2;j++) A[i][j] = nextInt();

}

static void solve() throws Exception {

int cnt = 0;
for(int i=1;i<=N;i++){
int emin = 12345, idx = -1;
for(int j=0;j<M;j++) if(!received[j] && A[j][0] <= i && A[j][1] >= i) {
if(A[j][1] < emin){
emin = A[j][1];
idx = j;
}
}
if(idx != -1) {
received[idx] = true;
cnt++;
}

}
bw.write(cnt + "\n");

}

}
```