From 6b0583a21b99a5a15067f15ef39e5517072c7bf5 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Wed, 10 Sep 2025 23:35:12 +0900 Subject: [PATCH 001/143] =?UTF-8?q?[20250910]=20BOJ=20/=20G2=20/=20?= =?UTF-8?q?=EC=A4=91=EC=95=99=EA=B0=92=20=EA=B5=AC=ED=95=98=EA=B8=B0=20/?= =?UTF-8?q?=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 \352\265\254\355\225\230\352\270\260.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" diff --git "a/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" "b/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" new file mode 100644 index 00000000..d5c7f4ab --- /dev/null +++ "b/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" @@ -0,0 +1,62 @@ +```java +import java.io.*; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.StringTokenizer; + +public class BJ_2696_중앙값_구하기 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int T; + private static int M; + private static String s; + + private static Queue minq; + private static Queue maxq; + + public static void main(String[] args) throws IOException { + sol(); + } + + private static void sol() throws IOException { + T = Integer.parseInt(br.readLine()); + + while (T-- > 0) { + M = Integer.parseInt(br.readLine()); + + s = ""; + minq = new PriorityQueue<>(); + maxq = new PriorityQueue<>((a, b) -> b - a); + for (int i = 0; i < M; i++) { + if (i % 10 == 0) { + st = new StringTokenizer(br.readLine()); + } + + if (i % 2 == 0) { + maxq.offer(Integer.parseInt(st.nextToken())); + } else { + minq.offer(Integer.parseInt(st.nextToken())); + } + + if (!minq.isEmpty() && maxq.peek() > minq.peek()) { + minq.offer(maxq.poll()); + maxq.offer(minq.poll()); + } + + if (i % 2 == 0) { + s += maxq.peek() + (i > 2 && (i + 2) % 20 == 0 ? "\n" : " "); + } + } + bw.write(maxq.size() + "\n"); + bw.write(s + "\n"); + } + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file From 5d50374c328863cbec25edfc9cfb742d453905e9 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Fri, 22 Aug 2025 10:46:23 +0900 Subject: [PATCH 002/143] =?UTF-8?q?[20250822]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=97=B4=EC=87=A0=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../22 BOJ G1 \354\227\264\354\207\240.md" | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 "JHLEE325/202508/22 BOJ G1 \354\227\264\354\207\240.md" diff --git "a/JHLEE325/202508/22 BOJ G1 \354\227\264\354\207\240.md" "b/JHLEE325/202508/22 BOJ G1 \354\227\264\354\207\240.md" new file mode 100644 index 00000000..01948d07 --- /dev/null +++ "b/JHLEE325/202508/22 BOJ G1 \354\227\264\354\207\240.md" @@ -0,0 +1,114 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int h, w; + static char[][] map; + static boolean[][] visited; + static boolean[] key; + static List[] door; + static final int[] dr = {-1, 1, 0, 0}; + static final int[] dc = {0, 0, -1, 1}; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder out = new StringBuilder(); + + int T = Integer.parseInt(br.readLine().trim()); + for(int t=0;t(); + + String keys = br.readLine().trim(); + if (!keys.equals("0")) { + for (int i = 0; i < keys.length(); i++) { + char ch = keys.charAt(i); + if ('a' <= ch && ch <= 'z') key[ch - 'a'] = true; + } + } + + out.append(bfs()).append('\n'); + } + + System.out.print(out.toString()); + } + + static int bfs() { + visited = new boolean[h + 2][w + 2]; + Deque q = new ArrayDeque<>(); + q.offer(new int[]{0, 0}); + visited[0][0] = true; + + int docs = 0; + + while (!q.isEmpty()) { + int[] cur = q.poll(); + int r = cur[0], c = cur[1]; + + for (int d = 0; d < 4; d++) { + int nr = r + dr[d]; + int nc = c + dc[d]; + + if (nr < 0 || nr >= h + 2 || nc < 0 || nc >= w + 2) continue; + if (visited[nr][nc]) continue; + + char ch = map[nr][nc]; + + if (ch == '*') continue; + + if ('A' <= ch && ch <= 'Z') { + int idx = ch - 'A'; + if (!key[idx]) { + door[idx].add(new int[]{nr, nc}); + continue; + } + } + + if ('a' <= ch && ch <= 'z') { + int idx = ch - 'a'; + if (!key[idx]) { + key[idx] = true; + for (int[] pos : door[idx]) { + int rr = pos[0], cc = pos[1]; + if (!visited[rr][cc]) { + visited[rr][cc] = true; + q.offer(new int[]{rr, cc}); + } + } + door[idx].clear(); + } + map[nr][nc] = '.'; + } + + if (ch == '$') { + docs++; + map[nr][nc] = '.'; + } + + visited[nr][nc] = true; + q.offer(new int[]{nr, nc}); + } + } + + return docs; + } +} + +``` From 6d92c19ab1300915c43f85a0824effedb64dd45f Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 22 Aug 2025 14:00:54 +0900 Subject: [PATCH 003/143] =?UTF-8?q?[20250822]=20BOJ=20/=20P5=20/=20(Relati?= =?UTF-8?q?vely)=20Prime=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202508/22 BOJ P5 (Relatively) Prime.md | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 khj20006/202508/22 BOJ P5 (Relatively) Prime.md diff --git a/khj20006/202508/22 BOJ P5 (Relatively) Prime.md b/khj20006/202508/22 BOJ P5 (Relatively) Prime.md new file mode 100644 index 00000000..ddf0921f --- /dev/null +++ b/khj20006/202508/22 BOJ P5 (Relatively) Prime.md @@ -0,0 +1,111 @@ +```java +import java.awt.image.AreaAveragingScaleFilter; +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final long MOD = 998244353; + static long P, N, M; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + for(int T=io.nextInt(); T-->0; ) { + init(); + solve(); + } + + io.close(); + + } + + static void init() throws Exception { + + P = io.nextLong(); + N = io.nextLong(); + M = io.nextLong(); + + } + + static void solve() throws Exception { + + if(N < M) { + long t = N; + N = M; + M = t; + } + + long pm = power(P, M); + long ans = pm * ((power(pm, N/M) + MOD - 1) % MOD) % MOD; + ans = (ans * (power((pm+MOD-1)%MOD, MOD-2))) % MOD; + if(N%M != 0) ans = (ans + power(P, N)) % MOD; + + if(pm == 1) { + ans = N/M; + if(N%M != 0) ans = (ans + power(P, N)) % MOD; + } + io.write(ans + "\n"); + + } + + static long power(long a, long x) { + if(x == 0) return 1; + if(x == 1) return a%MOD; + long h = power(a, x>>1) % MOD; + if(x%2 == 0) return h*h%MOD; + return h*h%MOD*a%MOD; + } + +} +``` From 0afc51fdcc5cb3bd86ee676d9f7df77e20e12f89 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 22 Aug 2025 15:18:54 +0900 Subject: [PATCH 004/143] =?UTF-8?q?[20250822]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=8F=84=EC=8B=9C=20=EA=B1=B4=EC=84=A4=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\213\234 \352\261\264\354\204\244.md" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "suyeun84/202508/22 BOJ G4 \353\217\204\354\213\234 \352\261\264\354\204\244.md" diff --git "a/suyeun84/202508/22 BOJ G4 \353\217\204\354\213\234 \352\261\264\354\204\244.md" "b/suyeun84/202508/22 BOJ G4 \353\217\204\354\213\234 \352\261\264\354\204\244.md" new file mode 100644 index 00000000..fa2693ee --- /dev/null +++ "b/suyeun84/202508/22 BOJ G4 \353\217\204\354\213\234 \352\261\264\354\204\244.md" @@ -0,0 +1,61 @@ +```java +import java.util.*; +import java.io.*; + +public class boj21924 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static int N, M, cnt = 0; + static long answer; + static ArrayList> graph = new ArrayList<>(); + static boolean[] visited; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + M = nextInt(); + visited = new boolean[N+1]; + for (int i = 0; i <= N; i++) graph.add(new ArrayList()); + for (int i = 0; i < M; i++) { + nextLine(); + int a = nextInt(); + int b = nextInt(); + int c = nextInt(); + graph.get(a).add(new Node(b, c)); + graph.get(b).add(new Node(a, c)); + answer += c; + } + dijkstra(); + + if (cnt == N) System.out.println(answer); + else System.out.println(-1); + } + + static void dijkstra() { + PriorityQueue pq = new PriorityQueue<>((o1,o2) -> o1.c-o2.c); + pq.offer(new Node(1, 0)); + + while(!pq.isEmpty()) { + Node cur = pq.poll(); + if (visited[cur.v]) continue; + visited[cur.v] = true; + answer -= cur.c; + cnt++; + for (Node next : graph.get(cur.v)) { + if (visited[next.v]) continue; + pq.offer(next); + } + } + } + + static class Node { + int v, c; + public Node(int v, int c) { + this.v = v; + this.c = c; + } + } +} +``` From c6ab09dd8724fd0fd79c5e99e30598ca96db6f61 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Fri, 22 Aug 2025 16:54:50 +0900 Subject: [PATCH 005/143] =?UTF-8?q?[20250822]=20BOJ=20/=20P3=20/=20?= =?UTF-8?q?=ED=99=94=EB=A0=A4=ED=95=9C=20=EB=A7=88=EC=9D=84=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\244\355\225\234 \353\247\210\354\235\204" | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 "0224LJH/202508/22 BOJ \355\231\224\353\240\244\355\225\234 \353\247\210\354\235\204" diff --git "a/0224LJH/202508/22 BOJ \355\231\224\353\240\244\355\225\234 \353\247\210\354\235\204" "b/0224LJH/202508/22 BOJ \355\231\224\353\240\244\355\225\234 \353\247\210\354\235\204" new file mode 100644 index 00000000..8e63ce68 --- /dev/null +++ "b/0224LJH/202508/22 BOJ \355\231\224\353\240\244\355\225\234 \353\247\210\354\235\204" @@ -0,0 +1,166 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.StringTokenizer; + + +public class Main { + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringBuilder sb = new StringBuilder(); + static StringTokenizer st; + + static int houseCnt, nodeCnt, colorCnt, taskCnt; + + // 각각의 노드가 지금 구간에서 어떤 색을 몇 개 가지고 있는 지 인지해야함. + // 100,000 * 4 * 30 = 12,000,000 개의 Integer -> 이게 맞나? + + static class SegmentTree{ + + int[] lazy; + int check; + int[] nodes; // 어느 색상을 가지는지 비트마스킹으로 표현. 이래서 색상이 최대가 30이었구나 + + public SegmentTree() { + nodeCnt = houseCnt*4; + nodes = new int[nodeCnt]; + lazy = new int[nodeCnt]; + Arrays.fill(nodes, (1 << 1)); + } + + + + private void updateLazy(int nodeIdx, int from, int to) { + if (lazy[nodeIdx] ==0) return; + + nodes[nodeIdx] = ( 1 << lazy[nodeIdx]); + + if ( from != to) { + lazy[nodeIdx*2] = lazy[nodeIdx]; + lazy[nodeIdx*2+1] = lazy[nodeIdx]; + } + lazy[nodeIdx] = 0; + + return; + } + + public void updateRnage(int from, int to , int target) { + updateRange(1,1,houseCnt, from,to,target); + } + + private void updateRange (int idx, int start, int end, int from ,int to, int target) { + updateLazy(idx, start, end); + + if ( start > to || end < from) return; // 아예 안걸림 + + + // 완전히 걸림 + if ( start >= from && end <= to) { + + nodes[idx] = (1 << target); + + if (start!=end) { + lazy[idx*2] = target; + lazy[idx*2+1] = target; + } + return; + } + + //걸치는 경우 + + int mid = (start+end)/2; + + // 하위 노드를 업데이트 후 + updateRange(idx*2,start,mid,from,to,target); + updateRange(idx*2+1,mid+1,end,from,to,target); + + + nodes[idx] =( nodes[idx*2] | nodes[idx*2+1]); + } + + public int query (int from, int to) { + check = 0 ; + query(1, 1, houseCnt, from,to); + + int ans = 0; + + for (int i = 0; i < 30; i++) { + if ( (check & (1 << i)) != 0) ans++; + } + return ans; + } + + private void query(int idx, int start, int end, int from ,int to) { + updateLazy(idx, start, end); + + if (start > to || end < from) return; + + + if ( start >= from && end <= to) { + check |= nodes[idx]; + return; + } + + // 적당히 겹치는 경우 + int mid = (start+end)/2; + query(idx*2, start,mid,from,to); + query(idx*2+1, mid+1,end,from,to); + } + + } + + + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + + houseCnt = Integer.parseInt(st.nextToken()); + colorCnt = Integer.parseInt(st.nextToken()); + taskCnt = Integer.parseInt(st.nextToken()); + + } + + public static void process() throws IOException { + SegmentTree tree = new SegmentTree(); + + for (int i = 0; i < taskCnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + String order = st.nextToken(); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + + if (from > to) { + int temp = from; + from = to; + to = temp; + } + + if (order.equals("C")){ + int target = Integer.parseInt(st.nextToken()); + tree.updateRnage(from, to, target); + } else { + sb.append(tree.query(from, to)).append("\n"); + } + } + + } + + + + public static void print() { + System.out.print(sb.toString()); + } +} + +``` From 94bbbbd96877091f6cb74d99a36a4bb7bd095951 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Fri, 22 Aug 2025 23:14:16 +0900 Subject: [PATCH 006/143] =?UTF-8?q?[20250822]=20BOJ=20/=20P4=20/=20?= =?UTF-8?q?=EC=84=B8=EA=B8=88=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../22 BOJ P4 \354\204\270\352\270\210.md" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "lkhyun/202508/22 BOJ P4 \354\204\270\352\270\210.md" diff --git "a/lkhyun/202508/22 BOJ P4 \354\204\270\352\270\210.md" "b/lkhyun/202508/22 BOJ P4 \354\204\270\352\270\210.md" new file mode 100644 index 00000000..bbd5735e --- /dev/null +++ "b/lkhyun/202508/22 BOJ P4 \354\204\270\352\270\210.md" @@ -0,0 +1,108 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static class Edge{ + int to; + int cnt; + int cost; + + Edge(int to, int cnt, int cost){ + this.to = to; + this.cnt = cnt; + this.cost = cost; + } + } + static int N,M,K; + static int S,D; + static List[] adjLists; + static int[][] dist; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + adjLists = new List[N+1]; + dist = new int[N+1][N+1]; + + for (int i = 1; i <= N; i++) { + adjLists[i] = new ArrayList<>(); + Arrays.fill(dist[i], Integer.MAX_VALUE); + } + + st = new StringTokenizer(br.readLine()); + S = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + adjLists[from].add(new Edge(to, 0, cost)); + adjLists[to].add(new Edge(from, 0, cost)); + } + + dijkstra(S); + + int optIdx = 0; + int ans = Integer.MAX_VALUE; + for (int i = 1; i <= N; i++) { + if(dist[D][i] < ans){ + ans = dist[D][i]; + optIdx = i; + } + } + StringBuilder sb = new StringBuilder(); + sb.append(ans).append("\n"); + + int tax = 0; + for (int i = 0; i < K; i++) { + tax += Integer.parseInt(br.readLine()); + ans = Integer.MAX_VALUE; + for (int j = 1; j <= N; j++) { + if(dist[D][j] == Integer.MAX_VALUE) continue; + int cur = dist[D][j] + (tax*j); + if(cur < ans){ + ans = cur; + optIdx = j; + } + } + sb.append(ans).append("\n"); + } + bw.write(sb.toString()); + bw.close(); + } + + public static void dijkstra(int start){ + PriorityQueue pq = new PriorityQueue<>((a,b) -> a.cost - b.cost); + + dist[start][0] = 0; + pq.add(new Edge(start,0,0)); + + while(!pq.isEmpty()){ + Edge cur = pq.poll(); + + if(dist[cur.to][cur.cnt] < cur.cost) continue; + + for(Edge next : adjLists[cur.to]){ + int newCost = cur.cost + next.cost; + int nextCnt = cur.cnt + 1; + + if(nextCnt <= N && dist[next.to][nextCnt] > newCost){ + dist[next.to][nextCnt] = newCost; + pq.offer(new Edge(next.to, nextCnt, newCost)); + } + } + } + } +} + +``` From faa644b590292dc69638b0f4cdb1e1b715ea9d8e Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 22 Aug 2025 23:29:12 +0900 Subject: [PATCH 007/143] =?UTF-8?q?[20250822]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EC=A7=80=EA=B2=8C=EC=B0=A8=EC=99=80=20=ED=81=AC=EB=A0=88?= =?UTF-8?q?=EC=9D=B8=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \355\201\254\353\240\210\354\235\270.md" | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 "LiiNi-coder/202508/22 PGM \354\247\200\352\262\214\354\260\250\354\231\200 \355\201\254\353\240\210\354\235\270.md" diff --git "a/LiiNi-coder/202508/22 PGM \354\247\200\352\262\214\354\260\250\354\231\200 \355\201\254\353\240\210\354\235\270.md" "b/LiiNi-coder/202508/22 PGM \354\247\200\352\262\214\354\260\250\354\231\200 \355\201\254\353\240\210\354\235\270.md" new file mode 100644 index 00000000..40c7526d --- /dev/null +++ "b/LiiNi-coder/202508/22 PGM \354\247\200\352\262\214\354\260\250\354\231\200 \355\201\254\353\240\210\354\235\270.md" @@ -0,0 +1,113 @@ +```java +import java.util.*; + +class Solution { + static class Point{ + int r; + int c; + Point(int r, int c){ + this.r = r; + this.c = c; + } + Point translate(int dr, int dc){ + return new Point(r+dr, c+dc); + } + } + private static int[][] Drdcs = { + {0, 1}, + {1, 0}, + {0, -1}, + {-1, 0} + }; + private static int R; + private static int C; + private static int[][] Map; + private static HashMap> PointsOfId; + public int solution(String[] storages, String[] requests) { + C = storages[0].length(); + R = storages.length; + int answer = R*C; + Map = new int[R+2][C+2]; + PointsOfId = new HashMap>(); + for(int r = 0; r < R; r++){ + String storage = storages[r]; + for(int c = 0; c< C; c++){ + char cc = storage.charAt(c); + int id = cc - 'A' + 1; + var points = PointsOfId.get(id); + if(points == null){ + points = new LinkedList(); + PointsOfId.put(id, points); + } + points.add(new Point(r+1, c+1)); + Map[r+1][c+1] = id; + } + } + + Integer preTarget = null; + for(String request: requests){ + int target = request.charAt(0) - 'A'+1; + if(request.length() != 1){ + // for(Point p: PointsOfId.get(target)){ 런타임 에러!!!! + // Map[p.r][p.c] = 0; + // answer--; + // } + for(Point p: PointsOfId.getOrDefault(target, new LinkedList())){ + Map[p.r][p.c] = 0; + answer--; + } + continue; + } + var visited = new boolean[R+2][C+2]; + + var startP = new Point(0, 0); + visit(visited, startP); + var q = new ArrayDeque(); + q.offer(startP); + while(!q.isEmpty()){ + Point p = q.poll(); + for(int[] drdc: Drdcs){ + var nextP = p.translate(drdc[0], drdc[1]); + if(BC(nextP)) continue; + if(isVisit(visited, nextP)) continue; + if(getIdAt(nextP) == target){ + Map[nextP.r][nextP.c] = 0; + visit(visited, nextP); + }else if(getIdAt(nextP) == 0){ + visit(visited, nextP); + q.offer(nextP); + } + } + } + // p(Map); + // System.out.println(); + } + + int a2 = 0; + for(int r = 0; r= R+2 || c < 0 || c>=C+2; + } +} +``` From 6867d7e556a8e46977b4d5be8b5f7ec2512a902e Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Fri, 22 Aug 2025 23:34:58 +0900 Subject: [PATCH 008/143] =?UTF-8?q?[20250822]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=ED=95=98=EB=8A=98=EC=97=90=EC=84=9C=20=EB=B3=84=EB=98=A5?= =?UTF-8?q?=EB=B3=84=EC=9D=B4=20=EB=B9=97=EB=B0=9C=EC=B9=9C=EB=8B=A4=20/?= =?UTF-8?q?=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\271\227\353\260\234\354\271\234.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "Ukj0ng/202508/22 BOJ G3 \355\225\230\353\212\230\354\227\220\354\204\234 \353\263\204\353\230\245\353\263\204\354\235\264 \353\271\227\353\260\234\354\271\234.md" diff --git "a/Ukj0ng/202508/22 BOJ G3 \355\225\230\353\212\230\354\227\220\354\204\234 \353\263\204\353\230\245\353\263\204\354\235\264 \353\271\227\353\260\234\354\271\234.md" "b/Ukj0ng/202508/22 BOJ G3 \355\225\230\353\212\230\354\227\220\354\204\234 \353\263\204\353\230\245\353\263\204\354\235\264 \353\271\227\353\260\234\354\271\234.md" new file mode 100644 index 00000000..bc76116c --- /dev/null +++ "b/Ukj0ng/202508/22 BOJ G3 \355\225\230\353\212\230\354\227\220\354\204\234 \353\263\204\353\230\245\353\263\204\354\235\264 \353\271\227\353\260\234\354\271\234.md" @@ -0,0 +1,60 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[][] stars; + private static int N, M, L, K, answer; + + public static void main(String[] args) throws IOException { + init(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + answer = K; + int max = 0; + + stars = new int[K][2]; + + Set xCandidates = new HashSet<>(); + Set yCandidates = new HashSet<>(); + + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + stars[i][0] = Integer.parseInt(st.nextToken()); + stars[i][1] = Integer.parseInt(st.nextToken()); + xCandidates.add(stars[i][0]); + yCandidates.add(stars[i][1]); + } + + for (int x : xCandidates) { + for (int y : yCandidates) { + int count = 0; + + for (int i = 0; i < K; i++) { + if (stars[i][0] >= x && stars[i][0] <= x + L && + stars[i][1] >= y && stars[i][1] <= y + L) { + count++; + } + } + + max = Math.max(max, count); + } + } + + answer -= max; + } +} +``` From c0008f7eb852d7606e4de9445df5fa8f01512474 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 23 Aug 2025 11:31:21 +0900 Subject: [PATCH 009/143] =?UTF-8?q?[20250823]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=A6=AC=EB=AA=A8=EC=BB=A8=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\246\254\353\252\250\354\273\250.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" diff --git "a/Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" "b/Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" new file mode 100644 index 00000000..49fcdd64 --- /dev/null +++ "b/Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" @@ -0,0 +1,69 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static boolean[] used; + private static int N, M, answer; + + public static void main(String[] args) throws IOException { + init(); + + for (int i = 0; i <= 1000000; i++) { + if (canPush(i)) { + int n = Math.abs(N - i) + length(i); + answer = Math.min(answer, n); + } + } + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + answer = Math.abs(N - 100); + + used = new boolean[10]; + Arrays.fill(used, true); + + if (M > 0) { + StringTokenizer st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < M; i++) { + int n = Integer.parseInt(st.nextToken()); + used[n] = false; + } + } + } + + private static boolean canPush(int num) { + if (num == 0) return used[num]; + + while (num > 0) { + int n = num % 10; + if (!used[n]) return false; + num /= 10; + } + + return true; + } + + private static int length(int num) { + if (num == 0) return 1; + + int count = 0; + while (num > 0) { + count++; + num /= 10; + } + + return count; + } +} +``` From 89312304fcf9d12989ac75b7bb1b093b73481a6e Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 23 Aug 2025 12:37:00 +0900 Subject: [PATCH 010/143] =?UTF-8?q?Create=2023=20BOJ=20=EC=A2=8B=EC=9D=80?= =?UTF-8?q?=20=EB=B6=80=EB=B6=84=20=EB=AC=B8=EC=9E=90=EC=97=B4=EC=9D=98=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \352\260\234\354\210\230.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" diff --git "a/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" "b/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" new file mode 100644 index 00000000..42b74158 --- /dev/null +++ "b/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" @@ -0,0 +1,95 @@ +``` java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + + +public class Main { + + static int badLimit,len,ans; + static boolean[] isBad; + static char[] word; + + static class TrieNode{ + HashMap map = new HashMap<>(); + + public void dfs(int badCnt) { + if (badCnt > badLimit) { + return; + } + ans++; + + for (char c: map.keySet()) { + TrieNode child = map.get(c); + + if (isBad[c-'a']) child.dfs(badCnt+1); + else child.dfs(badCnt); + } + + + } + } + + static TrieNode root = new TrieNode(); + + + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String rawWord = br.readLine(); + len = rawWord.length(); + word = new char[len]; + + for (int i = 0 ; i < len; i++) { + word[i] = rawWord.charAt(i); + } + + String[] rawBadGood = br.readLine().split(""); + isBad = new boolean[26]; + for (int i = 0; i < 26; i++) { + isBad[i] = rawBadGood[i].equals("0"); + } + + badLimit = Integer.parseInt(br.readLine()); + ans = -1; + } + + public static void process() { + for (int i = 0; i < len; i++) { + insert(i); + } + + root.dfs(0); + + + + } + + public static void insert(int from) { + TrieNode node =root; + for (int i = from; i < len; i++) { + char ch = word[i]; + node = node.map.computeIfAbsent(ch, c -> new TrieNode()); + } + } + + + + + + + + public static void print() { + System.out.println(ans); + } +} + +``` From df09fdc81fef19b653df22251c602264f4296cb2 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 23 Aug 2025 12:37:51 +0900 Subject: [PATCH 011/143] =?UTF-8?q?[20250823]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=A2=8B=EC=9D=80=20=EB=B6=80=EB=B6=84=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=EC=9D=98=20=EA=B0=9C=EC=88=98=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From aa36e3af7d3879cbe32548600cbb762bffac11e0 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 23 Aug 2025 12:38:39 +0900 Subject: [PATCH 012/143] =?UTF-8?q?[20250823]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=A2=8B=EC=9D=80=20=EB=B6=80=EB=B6=84=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=EC=9D=98=20=EA=B0=9C=EC=88=98=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" "b/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" index 42b74158..b8b7f550 100644 --- "a/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" +++ "b/0224LJH/202508/23 BOJ \354\242\213\354\235\200 \353\266\200\353\266\204 \353\254\270\354\236\220\354\227\264\354\235\230 \352\260\234\354\210\230.md" @@ -4,7 +4,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.*; - + public class Main { static int badLimit,len,ans; From 8aae1a88c17a8e0063717013839d0c395424c2dc Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sat, 23 Aug 2025 20:30:14 +0900 Subject: [PATCH 013/143] =?UTF-8?q?[20250823]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=8B=A8=EC=96=B4=20=EC=88=98=ED=95=99=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\226\264 \354\210\230\355\225\231.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "JHLEE325/202508/23 BOJ G4 \353\213\250\354\226\264 \354\210\230\355\225\231.md" diff --git "a/JHLEE325/202508/23 BOJ G4 \353\213\250\354\226\264 \354\210\230\355\225\231.md" "b/JHLEE325/202508/23 BOJ G4 \353\213\250\354\226\264 \354\210\230\355\225\231.md" new file mode 100644 index 00000000..f58fc587 --- /dev/null +++ "b/JHLEE325/202508/23 BOJ G4 \353\213\250\354\226\264 \354\210\230\355\225\231.md" @@ -0,0 +1,37 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int N = Integer.parseInt(br.readLine()); + + int[] weight = new int[26]; + + for (int i = 0; i < N; i++) { + String word = br.readLine(); + int len = word.length(); + for (int j = 0; j < len; j++) { + char c = word.charAt(j); + weight[c - 'A'] += Math.pow(10, len - j - 1); + } + } + + PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); + for (int w : weight) { + if (w > 0) pq.add(w); + } + + int num = 9; + int sum = 0; + while (!pq.isEmpty()) { + int val = pq.poll(); + sum += val * num--; + } + + System.out.println(sum); + } +} + +``` From ec03e9280ff31e6f51d9cb0e712c343430b9e19e Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sat, 23 Aug 2025 22:11:40 +0900 Subject: [PATCH 014/143] =?UTF-8?q?[20250823]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EC=9D=B4=EB=AA=A8=ED=8B=B0=EC=BD=98=20=ED=95=A0=EC=9D=B8?= =?UTF-8?q?=ED=96=89=EC=82=AC=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\354\235\270\355\226\211\354\202\254.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "LiiNi-coder/202508/23 PGM \354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.md" diff --git "a/LiiNi-coder/202508/23 PGM \354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.md" "b/LiiNi-coder/202508/23 PGM \354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.md" new file mode 100644 index 00000000..9d8d76ab --- /dev/null +++ "b/LiiNi-coder/202508/23 PGM \354\235\264\353\252\250\355\213\260\354\275\230 \355\225\240\354\235\270\355\226\211\354\202\254.md" @@ -0,0 +1,74 @@ +```java +import java.util.*; +class Solution { + private static List combs; + private static int[] comb; + private static int[] coupons = new int[]{10, 20, 30, 40}; + private static int NOfE; + public int[] solution(int[][] users, int[] emoticons) { + NOfE = emoticons.length; + combs = new LinkedList(); + comb = new int[NOfE]; + var answer1 = 0; + var answer2 = 0; + //# 이모티콘 부분집합 for ex. 10, 20, 30, 30, 30... 4^7 + getComb(); + for(int[] combE : combs){ + //System.out.println(Arrays.toString(combE)); + int[] candidates = new int[2]; + //## 유저 for문 + int[] prices = new int[NOfE]; + for(int i = 0; i= uPrice){ + //System.out.println("넘음!"); + candidates[0] += 1; + continue outer; + } + } + candidates[1] += uTotal; + } + //System.out.println(String.format("중간결과: %d %d", candidates[0], candidates[1])); + boolean b1 = answer1 <= candidates[0]; + boolean b2 = answer2 <= candidates[1]; + if(answer1 == candidates[0]){ + if(answer2 <= candidates[1]){ + answer2 = candidates[1]; + } + }else if(answer1 < candidates[0]){ + answer1 = candidates[0]; + answer2 = candidates[1]; + } + + //### + } + + return new int[]{answer1, answer2}; + } + private void getComb(){ + dfs(0); + } + private void dfs(int index){ + if(index == NOfE){ + combs.add(comb.clone()); + return; + } + for(int coupon: coupons){ + comb[index] = coupon; + dfs(index+1); + } + } +} +``` From 66455eb2d19cb268d59c54a91e489c3570933258 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 23 Aug 2025 22:54:15 +0900 Subject: [PATCH 015/143] =?UTF-8?q?[20250823]=20BOJ=20/=20G2=20/=20?= =?UTF-8?q?=EB=AF=B8=ED=99=95=EC=9D=B8=20=EB=8F=84=EC=B0=A9=EC=A7=80=20/?= =?UTF-8?q?=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\217\204\354\260\251\354\247\200.md" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" diff --git "a/lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" "b/lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" new file mode 100644 index 00000000..b6af36a2 --- /dev/null +++ "b/lkhyun/202508/23 BOJ G2 \353\257\270\355\231\225\354\235\270 \353\217\204\354\260\251\354\247\200.md" @@ -0,0 +1,87 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static class Edge { + int to; + int cost; + + public Edge(int to, int cost) { + this.to = to; + this.cost = cost; + } + } + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + int repeat = Integer.parseInt(br.readLine()); + for(int test=0; test[] graph = new ArrayList[n+1]; + for(int i=1; i<=n; i++) { + graph[i] = new ArrayList<>(); + } + + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int x1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + + for(int i=0; i pq = new PriorityQueue<>((o1, o2) -> Integer.compare(o1.cost, o2.cost)); + pq.offer(new Edge(start, 0)); + dist[start] = 0; + + while(!pq.isEmpty()) { + Edge current = pq.poll(); + + if(dist[current.to] < current.cost) continue; + + for(Edge edge : graph[current.to]) { + int newCost = current.cost + edge.cost; + if(dist[edge.to] <= newCost) continue; + dist[edge.to] = newCost; + pq.offer(new Edge(edge.to, newCost)); + } + } + Arrays.sort(ends); + for(int end : ends) { + int cost = dist[end]; + if(cost%2 == 0) continue; + sb.append(end).append(" "); + } + sb.append("\n"); + } + + + System.out.println(sb.toString().trim()); + } +} +``` From 760cfc12fead615abc8799ba005e6479f1242913 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 23 Aug 2025 23:33:35 +0900 Subject: [PATCH 016/143] =?UTF-8?q?[20250823]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=B7=B8=EB=9E=98=ED=94=84=20=ED=83=90=EC=83=89=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\224\204 \355\203\220\354\203\211.md" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "khj20006/202508/23 BOJ G5 \352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211.md" diff --git "a/khj20006/202508/23 BOJ G5 \352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211.md" "b/khj20006/202508/23 BOJ G5 \352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211.md" new file mode 100644 index 00000000..cacc928c --- /dev/null +++ "b/khj20006/202508/23 BOJ G5 \352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211.md" @@ -0,0 +1,39 @@ +```cpp +#include +using namespace std; + +int main() { + cin.tie(0)->sync_with_stdio(0); + int N,M; + cin>>N>>M; + bool v[501][501]{}; + for(int i=0,a,b;i>a>>b; + v[a][b] = v[b][a] = 1; + } + int Q; + for(cin>>Q;Q--;) { + int a,b,c; + cin>>a>>b>>c; + int d = a&1; + v[b][c] = v[c][b] = d; + + int ans[501]{}; + for(int i=1;i<=N;i++) ans[i] = -1; + queue> q; + q.emplace(1,0); + bitset<501> vis; + vis[1] = 1; + while(!q.empty()) { + auto [n,t] = q.front(); q.pop(); + ans[n] = t; + for(int i=1;i<=N;i++) if(v[n][i] && !vis[i]) { + vis[i] = 1; + q.emplace(i,t+1); + } + } + for(int i=1;i<=N;i++) cout< Date: Sun, 24 Aug 2025 09:53:54 +0900 Subject: [PATCH 017/143] =?UTF-8?q?[20250824]=20BOJ=20/=20G4=20/=20Elder?= =?UTF-8?q?=20price=20robot=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ukj0ng/202508/24 BOJ G4 Elder price robot.md | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Ukj0ng/202508/24 BOJ G4 Elder price robot.md diff --git a/Ukj0ng/202508/24 BOJ G4 Elder price robot.md b/Ukj0ng/202508/24 BOJ G4 Elder price robot.md new file mode 100644 index 00000000..423cad74 --- /dev/null +++ b/Ukj0ng/202508/24 BOJ G4 Elder price robot.md @@ -0,0 +1,49 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[] arr, answer; + private static Stack stack; + private static int N; + + public static void main(String[] args) throws IOException { + init(); + solve(); + + for (int i = 0; i < N; i++) { + if (answer[i] != -1) bw.write(answer[i] + "\n"); + else bw.write("infinity" + "\n"); + } + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + arr = new int[N]; + answer = new int[N]; + stack = new Stack<>(); + Arrays.fill(answer, -1); + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + } + + private static void solve() { + for (int i = 0; i < N; i++) { + while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) { + int idx = stack.pop(); + answer[idx] = i - idx; + } + stack.push(i); + } + } +} +``` From b780b9b7115dca5ccc8bed0466791bf34ee61da1 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sun, 24 Aug 2025 13:52:17 +0900 Subject: [PATCH 018/143] =?UTF-8?q?[20250824]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=9D=B4=EB=B6=84=20=EA=B7=B8=EB=9E=98=ED=94=84=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\267\270\353\236\230\355\224\204.md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "JHLEE325/202508/24 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" diff --git "a/JHLEE325/202508/24 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" "b/JHLEE325/202508/24 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" new file mode 100644 index 00000000..00568b37 --- /dev/null +++ "b/JHLEE325/202508/24 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" @@ -0,0 +1,75 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static ArrayList[] graph; + static int[] color; + static int v, e; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + StringBuilder sb = new StringBuilder(); + int T = Integer.parseInt(br.readLine()); + + for (int t = 0; t < T; t++) { + st = new StringTokenizer(br.readLine()); + v = Integer.parseInt(st.nextToken()); + e = Integer.parseInt(st.nextToken()); + + graph = new ArrayList[v + 1]; + for (int i = 1; i <= v; i++) graph[i] = new ArrayList<>(); + + for (int i = 0; i < e; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + graph[a].add(b); + graph[b].add(a); + } + + color = new int[v + 1]; + boolean ok = true; + + for (int i = 1; i <= v && ok; i++) { + if (color[i] == 0) { + ok = bfs(i); + } + } + + if(ok){ + sb.append("YES\n"); + } + else{ + sb.append("NO\n"); + } + } + + System.out.print(sb.toString()); + } + + static boolean bfs(int s) { + ArrayDeque q = new ArrayDeque<>(); + color[s] = 1; + q.offer(s); + + while (!q.isEmpty()) { + int u = q.poll(); + int nextColor = -color[u]; + + for (int v : graph[u]) { + if (color[v] == 0) { + color[v] = nextColor; + q.offer(v); + } else if (color[v] == color[u]) { + return false; + } + } + } + return true; + } +} + +``` From 800e2905244e85689fb093405f67053dfc830935 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sun, 24 Aug 2025 21:37:51 +0900 Subject: [PATCH 019/143] =?UTF-8?q?[20250824]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=8F=99=EC=A0=84=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../24 BOJ \353\217\231\354\240\204.md" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "0224LJH/202508/24 BOJ \353\217\231\354\240\204.md" diff --git "a/0224LJH/202508/24 BOJ \353\217\231\354\240\204.md" "b/0224LJH/202508/24 BOJ \353\217\231\354\240\204.md" new file mode 100644 index 00000000..257bf8ac --- /dev/null +++ "b/0224LJH/202508/24 BOJ \353\217\231\354\240\204.md" @@ -0,0 +1,57 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int coinCnt,goal,ans; + static int[] coin,dp; + + + + public static void main(String[] args) throws IOException { + int TC = Integer.parseInt(br.readLine()); + for (int tc = 1; tc <= TC; tc++) { + init(); + process(); + print(); + } + } + + public static void init() throws IOException { + coinCnt = Integer.parseInt(br.readLine()); + coin = new int[coinCnt]; + ans = 0; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < coinCnt; i++) { + coin[i] = Integer.parseInt(st.nextToken()); + } + goal = Integer.parseInt(br.readLine()); + dp = new int[goal+1]; + dp[0] = 1; + + } + + public static void process() { + for (int i = 0; i < coinCnt; i++) { + int num = coin[i]; + for (int j = 0; j <= goal - num; j++) { + dp[j+num] += dp[j]; + } + } + ans = dp[goal]; + + } + + + + + public static void print() { + System.out.println(ans); + } +} +``` From 5de42b94e9b1a2722fdf0e0e312642b3b81b9c8e Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 24 Aug 2025 21:53:18 +0900 Subject: [PATCH 020/143] =?UTF-8?q?[20250824]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=86=8C=EC=85=9C=20=EB=84=A4=ED=8A=B8=EC=9B=8C=ED=82=B9=20?= =?UTF-8?q?=EC=96=B4=ED=94=8C=EB=A6=AC=EC=BC=80=EC=9D=B4=EC=85=98=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\354\274\200\354\235\264\354\205\230.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "lkhyun/202508/24 BOJ G5 \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" diff --git "a/lkhyun/202508/24 BOJ G5 \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" "b/lkhyun/202508/24 BOJ G5 \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" new file mode 100644 index 00000000..c6cdc31c --- /dev/null +++ "b/lkhyun/202508/24 BOJ G5 \354\206\214\354\205\234 \353\204\244\355\212\270\354\233\214\355\202\271 \354\226\264\355\224\214\353\246\254\354\274\200\354\235\264\354\205\230.md" @@ -0,0 +1,60 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + + public static void main(String[] args) throws IOException { + int testcase = Integer.parseInt(br.readLine()); + for(int t = 1 ; t <= testcase ; t++){ + bw.write("Scenario " + t + ":\n"); + int n = Integer.parseInt(br.readLine()); + int k = Integer.parseInt(br.readLine()); + int[] root = new int[n+1]; + for (int i = 0; i < n; i++) { + root[i] = i; + } + + for (int i = 0; i < k; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + union(a,b,root); + } + + int m = Integer.parseInt(br.readLine()); + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + if(find(a,root) == find(b,root)) bw.write("1\n"); + else bw.write("0\n"); + } + bw.write("\n"); + } + + bw.close(); + } + public static int find(int cur, int[] root){ + if(cur == root[cur]) return cur; + else return root[cur] = find(root[cur], root); + } + public static void union(int a,int b, int[] root){ + int rootA = find(a, root); + int rootB = find(b, root); + + if(rootA != rootB){ + if(rootA < rootB){ + root[rootA] = rootB; + }else{ + root[rootB] = rootA; + } + } + } +} + +``` From dce887a7e0d228f842c3dd1fd06691b7436b039c Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sun, 24 Aug 2025 23:18:11 +0900 Subject: [PATCH 021/143] =?UTF-8?q?[20250824]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EC=84=9D=EC=9C=A0=20=EC=8B=9C=EC=B6=94=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\354\234\240 \354\213\234\354\266\224.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" diff --git "a/LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" "b/LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" new file mode 100644 index 00000000..e4b7c928 --- /dev/null +++ "b/LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" @@ -0,0 +1,74 @@ +```java +import java.util.*; + +class Solution { + private static int R + private static int C; + private static int[][] land; + private static int[][] idAtPoint; + private static boolean[][] visited; + private static int[] dr = {1, -1, 0, 0}; + private static int[] dc = {0, 0, 1, -1}; + private static List countAtId; + + public int solution(int[][] lland) { + land = lland; + R = land.length; + C = land[0].length; + visited = new boolean[R][C]; + idAtPoint = new int[R][C]; + countAtId = new ArrayList<>(); + countAtId.add(0);//0생략 + int id = 1; + for(int r=0; r(); + for(int r=0; r(); + q.add(new int[]{sr, sc}); + visited[sr][sc] = true; + idAtPoint[sr][sc] = id; + + int temp = 0; + while(!q.isEmpty()){ + int[] cur = q.poll(); + int r = cur[0] + int c = cur[1]; + temp++; + for(int d=0; d<4; d++){ + int nr = r + dr[d]; + int nc = c + dc[d]; + if(nr<0 || nr>=R || nc<0 || nc>=C) continue; + if(visited[nr][nc]) continue; + if(land[nr][nc] == 0) continue; + visited[nr][nc] = true; + idAtPoint[nr][nc] = id; + q.add(new int[]{nr, nc}); + } + } + countAtId.add(temp); + } +} + +``` From 66289d866d728168d6b516308d2fd45c1e82678f Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sun, 24 Aug 2025 23:25:05 +0900 Subject: [PATCH 022/143] =?UTF-8?q?[20250824]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=81=9D=EB=82=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=8C=8C?= =?UTF-8?q?=ED=8B=B0=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\353\212\224 \355\214\214\355\213\260.md" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "suyeun84/202508/24 BOJ G4 \353\201\235\353\202\230\354\247\200 \354\225\212\353\212\224 \355\214\214\355\213\260.md" diff --git "a/suyeun84/202508/24 BOJ G4 \353\201\235\353\202\230\354\247\200 \354\225\212\353\212\224 \355\214\214\355\213\260.md" "b/suyeun84/202508/24 BOJ G4 \353\201\235\353\202\230\354\247\200 \354\225\212\353\212\224 \355\214\214\355\213\260.md" new file mode 100644 index 00000000..88ffb046 --- /dev/null +++ "b/suyeun84/202508/24 BOJ G4 \353\201\235\353\202\230\354\247\200 \354\225\212\353\212\224 \355\214\214\355\213\260.md" @@ -0,0 +1,44 @@ +```java +import java.io.*; +import java.util.*; + +public class boj11265 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + int M = nextInt(); + int[][] cost = new int[N+1][N+1]; + for (int i = 1; i < N+1; i++) { + nextLine(); + for(int j = 1; j < N+1; j++){ + cost[i][j] = nextInt(); + } + } + for(int middle = 1; middle < N+1; middle++){ + for(int start = 1; start < N+1; start++){ + for(int end = 1; end < N+1; end++){ + cost[start][end] = Math.min(cost[start][end], cost[start][middle]+cost[middle][end]); + } + } + } + for (int i = 0; i < M; i++) { + nextLine(); + int a = nextInt(); + int b = nextInt(); + long c = Long.parseLong(st.nextToken()); + if(cost[a][b] <= c) { + sb.append("Enjoy other party").append("\n"); + } else { + sb.append("Stay here").append("\n"); + } + } + System.out.println(sb); + } +} +``` From ff9719953f30b6dfda3befcdd046348c993425a6 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 24 Aug 2025 23:49:31 +0900 Subject: [PATCH 023/143] =?UTF-8?q?[20250824]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=ED=8A=B9=EC=88=98=20=EB=8A=A5=EB=A0=A5=20/=20=EA=B6=8C?= =?UTF-8?q?=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\210\230 \353\212\245\353\240\245.md" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" diff --git "a/khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" "b/khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" new file mode 100644 index 00000000..431bd974 --- /dev/null +++ "b/khj20006/202508/24 BOJ P5 \355\212\271\354\210\230 \353\212\245\353\240\245.md" @@ -0,0 +1,120 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + + static int N, M, C; + static int[][] min, max; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + M = io.nextInt(); + C = io.nextInt(); + min = new int[N+1][N+1]; + max = new int[N+1][N+1]; + for(int i=1;i<=N;i++) { + Arrays.fill(min[i], INF); + Arrays.fill(max[i], -INF); + } + for(int i=0;i pq = new PriorityQueue<>((a,b) -> a[0]-b[0]); + pq.offer(new int[]{0,1,0}); + while(!pq.isEmpty()) { + int[] cur = pq.poll(); + int d = cur[0], n = cur[1], t = cur[2]; + if(d > dist[n]) continue; + for(int i=1;i<=N;i++) if(min[n][i] != INF) { + if(t d - max[n][i]) { + dist[i] = d - max[n][i]; + pq.offer(new int[]{dist[i], i, t+1}); + } + if(dist[i] > d + min[n][i]) { + dist[i] = d + min[n][i]; + pq.offer(new int[]{dist[i], i, t}); + } + } + } + io.write(dist[N] + "\n"); + + } + +} +``` From 05e87ebe4046c90d0f1e0056d71111960f903b10 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Mon, 25 Aug 2025 08:15:45 +0900 Subject: [PATCH 024/143] =?UTF-8?q?[20250825]=20BOJ=20/=20G2=20/=20Escape?= =?UTF-8?q?=20Room=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ukj0ng/202508/25 BOJ G2 Escape Room.md | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Ukj0ng/202508/25 BOJ G2 Escape Room.md diff --git a/Ukj0ng/202508/25 BOJ G2 Escape Room.md b/Ukj0ng/202508/25 BOJ G2 Escape Room.md new file mode 100644 index 00000000..920c5b8b --- /dev/null +++ b/Ukj0ng/202508/25 BOJ G2 Escape Room.md @@ -0,0 +1,83 @@ +```import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static List[] d; + private static int[][] map; + private static boolean[][] visited; + private static int N, M; + public static void main(String[] args) throws IOException { + init(); + + bw.write(BFS(1, 1) + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + + map = new int[N+1][M+1]; + visited = new boolean[N+1][M+1]; + d = new List[1000001]; + + for (int i = 0; i < 1000001; i++) { + d[i] = new ArrayList<>(); + } + + for (int i = 1; i <= N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 1; j <= M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + } + + private static String BFS(int x, int y) { + Queue q = new ArrayDeque<>(); + visited[x][y] = true; + q.add(new int[] {x, y}); + + while (!q.isEmpty()) { + int[] current = q.poll(); + if (current[0] == N && current[1] == M) { + return "yes"; + } + + if (d[map[current[0]][current[1]]].size() == 0) { + findFactor(map[current[0]][current[1]]); + } + + for (int[] element : d[map[current[0]][current[1]]]) { + for (int i = 0; i < element.length; i++) { + int nx = element[i]; + int ny = element[i^1]; + + if (OOB(nx, ny) || visited[nx][ny]) continue; + visited[nx][ny] = true; + q.add(new int[] {nx, ny}); + } + } + } + + return "no"; + } + + private static void findFactor(int n) { + for (int i = 1; i <= Math.sqrt(n); i++) { + if (n % i == 0) { + d[n].add(new int[] {i, n / i}); + } + } + } + + private static boolean OOB(int nx, int ny) { + return nx < 1 || nx > N || ny < 1 || ny > M; + } +} + +``` From 890f276f9adbfa0b6a6c8b5b54cc04b977ffff49 Mon Sep 17 00:00:00 2001 From: zinnnn37 <102711874+zinnnn37@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:55:45 +0900 Subject: [PATCH 025/143] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c35f97f..4326ff2f 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ - + From ad6b4dd72e5e7f9c29ed73696fa97a2c41fa3685 Mon Sep 17 00:00:00 2001 From: zinnnn37 <102711874+zinnnn37@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:56:13 +0900 Subject: [PATCH 026/143] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4326ff2f..bd5bce54 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@

Solved.ac 프로필

Solved.ac 프로필

Solved.ac 프로필

Solved.ac 프로필
- + From b7cecf51d7e2182511939d31462be0f453904dbb Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Mon, 25 Aug 2025 12:15:17 +0900 Subject: [PATCH 027/143] =?UTF-8?q?[20250825]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=B6=88=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "JHLEE325/202508/25 BOJ G4 \353\266\210.md" | 112 ++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 "JHLEE325/202508/25 BOJ G4 \353\266\210.md" diff --git "a/JHLEE325/202508/25 BOJ G4 \353\266\210.md" "b/JHLEE325/202508/25 BOJ G4 \353\266\210.md" new file mode 100644 index 00000000..3d83f513 --- /dev/null +++ "b/JHLEE325/202508/25 BOJ G4 \353\266\210.md" @@ -0,0 +1,112 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int[][] map; + static int w, h; + static Queue fireQ; + static Queue humanQ; + static StringBuilder sb = new StringBuilder(); + static int[] dr = {-1, 1, 0, 0}; + static int[] dc = {0, 0, -1, 1}; + static boolean[][] fireVisited; + static boolean[][] humanVisited; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int T = Integer.parseInt(br.readLine()); + + for (int t = 0; t < T; t++) { + st = new StringTokenizer(br.readLine()); + w = Integer.parseInt(st.nextToken()); + h = Integer.parseInt(st.nextToken()); + + map = new int[h][w]; + fireVisited = new boolean[h][w]; + humanVisited = new boolean[h][w]; + + fireQ = new ArrayDeque<>(); + humanQ = new ArrayDeque<>(); + + int sr = -1, sc = -1; + + for (int i = 0; i < h; i++) { + String str = br.readLine(); + for (int j = 0; j < w; j++) { + char ch = str.charAt(j); + if (ch == '#') { + map[i][j] = 1; + } else { + map[i][j] = 0; + if (ch == '@') { + humanQ.add(new int[]{i, j}); + humanVisited[i][j] = true; + sr = i; sc = j; + } else if (ch == '*') { + fireQ.add(new int[]{i, j}); + fireVisited[i][j] = true; + } + } + } + } + + if (sr == 0 || sr == h - 1 || sc == 0 || sc == w - 1) { + sb.append("1\n"); + } else { + bfs(); + } + } + System.out.print(sb.toString()); + } + + public static void bfs() { + int time = 1; + + while (!humanQ.isEmpty()) { + int fs = fireQ.size(); + for (int i = 0; i < fs; i++) { + int[] cur = fireQ.poll(); + for (int d = 0; d < 4; d++) { + int nr = cur[0] + dr[d]; + int nc = cur[1] + dc[d]; + if (nr < 0 || nr >= h || nc < 0 || nc >= w) continue; + if (map[nr][nc] == 1 || fireVisited[nr][nc]) continue; + fireVisited[nr][nc] = true; + fireQ.add(new int[]{nr, nc}); + } + } + + int hs = humanQ.size(); + for (int i = 0; i < hs; i++) { + int[] cur = humanQ.poll(); + + if (cur[0] == 0 || cur[0] == h - 1 || cur[1] == 0 || cur[1] == w - 1) { + sb.append(time).append('\n'); + humanQ.clear(); + fireQ.clear(); + return; + } + + for (int d = 0; d < 4; d++) { + int nr = cur[0] + dr[d]; + int nc = cur[1] + dc[d]; + if (nr < 0 || nr >= h || nc < 0 || nc >= w) continue; + if (map[nr][nc] == 1) continue; + if (humanVisited[nr][nc]) continue; + if (fireVisited[nr][nc]) continue; + humanVisited[nr][nc] = true; + humanQ.add(new int[]{nr, nc}); + } + } + time++; + } + + sb.append("IMPOSSIBLE\n"); + } +} + +``` From 1f1b08fc1f76e0d2d55525edc8cc303eaba28fa2 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 25 Aug 2025 13:11:48 +0900 Subject: [PATCH 028/143] =?UTF-8?q?[20250825]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=B0=9C=EB=98=A5=EB=B2=8C=EB=A0=88=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\230\245\353\262\214\353\240\210.md" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "suyeun84/202508/25 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" diff --git "a/suyeun84/202508/25 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" "b/suyeun84/202508/25 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" new file mode 100644 index 00000000..4075e82b --- /dev/null +++ "b/suyeun84/202508/25 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" @@ -0,0 +1,45 @@ +```java +import java.util.*; +import java.io.*; + +public class boj3020 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + int H = nextInt(); + + int[] A = new int[H + 1]; + int[] B = new int[H + 1]; + + for (int n = 0; n < N; n += 2) { + nextLine(); + A[nextInt()]++; + nextLine(); + B[nextInt()]++; + } + + for (int h = H - 1; 0 < h; h--) { + A[h] += A[h + 1]; + B[h] += B[h + 1]; + } + + int count = 0; + int min = N; + + for (int h = H; 0 < h; h--) { + if (A[h] + B[H - h + 1] < min) { + count = 1; + min = A[h] + B[H - h + 1]; + } else if (A[h] + B[H - h + 1] == min) { + count++; + } + } + System.out.println(min + " " + count); + } +} +``` From 748b5fa598d14c34200acad72685bb3ad89e5557 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 25 Aug 2025 14:41:08 +0900 Subject: [PATCH 029/143] =?UTF-8?q?[20250825]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EB=B3=B4=EB=AC=BC=20=EC=B0=BE=EA=B8=B0=202=20/=20=EC=9D=B4?= =?UTF-8?q?=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\254\274 \354\260\276\352\270\260 2.md" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "lkhyun/202508/25 BOJ G3 \353\263\264\353\254\274 \354\260\276\352\270\260 2.md" diff --git "a/lkhyun/202508/25 BOJ G3 \353\263\264\353\254\274 \354\260\276\352\270\260 2.md" "b/lkhyun/202508/25 BOJ G3 \353\263\264\353\254\274 \354\260\276\352\270\260 2.md" new file mode 100644 index 00000000..2a8a02f3 --- /dev/null +++ "b/lkhyun/202508/25 BOJ G3 \353\263\264\353\254\274 \354\260\276\352\270\260 2.md" @@ -0,0 +1,79 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + static int H,W; + static char[][] map; + static int starti,startj; + static int[] di = {-1,0,1,1,1,0,-1,-1}; + static int[] dj = {1,1,1,0,-1,-1,-1,0}; + + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + H = Integer.parseInt(st.nextToken()); + W = Integer.parseInt(st.nextToken()); + + map = new char[H][W]; + + for (int i = 0; i < H; i++) { + char[] line = br.readLine().toCharArray(); + for (int j = 0; j < W; j++) { + map[i][j] = line[j]; + if(line[j] == 'K'){ + starti = i; + startj = j; + } + } + } + + bw.write(BFS()+""); + bw.close(); + } + public static int BFS(){ + ArrayDeque q = new ArrayDeque<>(); + int[][] dist = new int[H][W]; + for (int i = 0; i < H; i++) { + Arrays.fill(dist[i], Integer.MAX_VALUE); + } + q.offer(new int[]{starti,startj,0}); + dist[starti][startj] = 0; + + while(!q.isEmpty()){ + int[] cur = q.poll(); + if(map[cur[0]][cur[1]] == '*') return dist[cur[0]][cur[1]]; + if(dist[cur[0]][cur[1]] < cur[2]) continue; + + for (int k = 0; k < 3; k++) { + int ni = cur[0] + di[k]; + int nj = cur[1] + dj[k]; + if(check(ni,nj)){ + if(dist[ni][nj] > cur[2]){ + q.addFirst(new int[]{ni,nj,cur[2]}); + dist[ni][nj] = cur[2]; + } + } + } + for (int k = 3; k < 8; k++) { + int ni = cur[0] + di[k]; + int nj = cur[1] + dj[k]; + if(check(ni,nj)){ + if(dist[ni][nj] > cur[2]+1){ + q.addLast(new int[]{ni,nj,cur[2]+1}); + dist[ni][nj] = cur[2]+1; + } + } + } + } + return -1; + } + public static boolean check(int i, int j){ + if(i < 0 || i >= H || j < 0 || j >= W || map[i][j] == '#') return false; + return true; + } +} +``` From 34a328164156c107a7a84f7163dfbd1fc38faa99 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 25 Aug 2025 15:08:31 +0900 Subject: [PATCH 030/143] =?UTF-8?q?[20250825]=20=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=A2=8B=EB=8B=A4=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../25 BOJ \354\242\213\353\213\244.md" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "0224LJH/202508/25 BOJ \354\242\213\353\213\244.md" diff --git "a/0224LJH/202508/25 BOJ \354\242\213\353\213\244.md" "b/0224LJH/202508/25 BOJ \354\242\213\353\213\244.md" new file mode 100644 index 00000000..080bfe71 --- /dev/null +++ "b/0224LJH/202508/25 BOJ \354\242\213\353\213\244.md" @@ -0,0 +1,87 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.StringTokenizer; + + +public class Main { + + static int numCnt,ans; + static int[] arr; + static HashMap> good; + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + good = new HashMap<>(); + + numCnt = Integer.parseInt(br.readLine()); + arr =new int[numCnt]; + ans = 0; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < numCnt; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + } + + public static void process() throws IOException { + for (int i = 0; i ()); + good.get(arr[i]).add(i); + } + } + + + for (int i = 0; i < numCnt; i++) { + for (int j = i+1; j < numCnt; j++){ + int sum = arr[i] + arr[j]; + + if (!good.containsKey(sum)) continue; + + HashSet idx = good.get(sum); + + boolean isRemovable = false; + + for (int n: idx) { + if (n != i && n != j) { + isRemovable = true; + break; + } + } + + if (isRemovable) good.remove(sum); + + } + } + + int zeroCnt = 0; + for (int i = 0; i < numCnt; i++) if(arr[i] == 0) zeroCnt++; + if (zeroCnt >= 3) good.remove(0); + + for (int i = 0; i < numCnt; i++) { + if (!good.containsKey(arr[i])) ans++; + } + + } + + + + public static void print() { + System.out.println(ans); + } +} + +``` From 06f327046d3fa42a01f163caea18b0e6316c9485 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Mon, 25 Aug 2025 23:58:45 +0900 Subject: [PATCH 031/143] =?UTF-8?q?[20250825]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=B1=80=EA=B3=BC=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\246\254 \352\262\214\354\236\204.md" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "LiiNi-coder/202508/25 BOJ \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" diff --git "a/LiiNi-coder/202508/25 BOJ \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" "b/LiiNi-coder/202508/25 BOJ \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" new file mode 100644 index 00000000..c9b45ec4 --- /dev/null +++ "b/LiiNi-coder/202508/25 BOJ \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" @@ -0,0 +1,49 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + private static BufferedReader br; + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + String[] temp = br.readLine().split(" "); + int N = Integer.parseInt(temp[0]); + int M = Integer.parseInt(temp[1]); + + Map move = new HashMap<>(); + for (int i = 0; i < N; i++) { + temp = br.readLine().split(" "); + move.put(Integer.parseInt(temp[0]), Integer.parseInt(temp[1])); + } + for (int i = 0; i < M; i++) { + temp = br.readLine().split(" "); + move.put(Integer.parseInt(temp[0]), Integer.parseInt(temp[1])); + } + boolean[] visited = new boolean[101]; + Queue q = new ArrayDeque<>(); + q.add(new int[]{1, 0}); //QElement: {현재칸, 주사위횟수} + visited[1] = true; + while (!q.isEmpty()) { + // + int[] cur = q.poll(); + int now = cur[0]; + int count = cur[1]; + if (now == 100) { + System.out.println(count); + return; + } + + for (int d = 1; d <= 6; d++) { + int np = now + d; + if (np > 100) continue; + if (move.containsKey(np)) + np = move.get(np); + if (!visited[np]) { + visited[np] = true; + q.add(new int[]{np, count + 1}); + } + } + } + } +} +``` From 5551495f92689c5a709bb893d2872b51fa3828ae Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 25 Aug 2025 23:52:11 +0900 Subject: [PATCH 032/143] =?UTF-8?q?[20250825]=20BOJ=20/=20P4=20/=20?= =?UTF-8?q?=EA=B0=80=ED=9D=AC=EC=9D=98=20=EC=88=98=EC=97=B4=EB=86=80?= =?UTF-8?q?=EC=9D=B4=20(Large)=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...27\264\353\206\200\354\235\264 (Large).md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" diff --git "a/khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" "b/khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" new file mode 100644 index 00000000..e0b08010 --- /dev/null +++ "b/khj20006/202508/25 BOJ P4 \352\260\200\355\235\254\354\235\230 \354\210\230\354\227\264\353\206\200\354\235\264 (Large).md" @@ -0,0 +1,47 @@ +```cpp +#include +using namespace std; + +int Q, MOD; +vector pos[1000001]{}; +stack st; +set s; + +int main(){ + cin.tie(0)->sync_with_stdio(0); + + cin>>Q>>MOD; + if(MOD > Q) { + for(int o,a;Q--;) { + cin>>o; + if(o == 1) cin>>a; + if(o == 3) cout<<"-1\n"; + } + return 0; + } + + for(int i=0,o,a;i>o; + if(o == 1) { + cin>>a; + a %= MOD; + if(!pos[a].empty()) s.erase(pos[a].back()); + s.insert(st.size()); + pos[a].push_back(st.size()); + st.push(a); + } + else if(o == 2) { + if(st.empty()) continue; + a = st.top(); st.pop(); + s.erase(pos[a].back()); + pos[a].pop_back(); + if(!pos[a].empty()) s.insert(pos[a].back()); + } + else { + if(s.size() != MOD) cout<<"-1\n"; + else cout< Date: Tue, 26 Aug 2025 13:44:38 +0900 Subject: [PATCH 033/143] =?UTF-8?q?[20250826]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=B5=9C=EC=86=9F=EA=B0=92=EA=B3=BC=20=EC=B5=9C=EB=8C=93?= =?UTF-8?q?=EA=B0=92=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\265\234\353\214\223\352\260\222.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" diff --git "a/JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" "b/JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" new file mode 100644 index 00000000..d01c04b8 --- /dev/null +++ "b/JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" @@ -0,0 +1,95 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + int[] arr = new int[n]; + for(int i=0;i end || right < start) { + return -1; + } + if (left <= start && end <= right) { + return tree[node]; + } + int lmin = query(tree, node*2, start, (start+end)/2, left, right); + int rmin = query(tree, node*2+1, (start+end)/2+1, end, left, right); + if (lmin == -1) { + return rmin; + } else if (rmin == -1) { + return lmin; + } else { + return Math.min(lmin, rmin); + } + } + + static void initmax(int[] arr, int[] tree, int node, int start, int end) { + if (start == end) { + tree[node] = arr[start]; + } else { + initmax(arr, tree, node * 2, start, (start + end) / 2); + initmax(arr, tree, node * 2 + 1, (start + end) / 2 + 1, end); + tree[node] = Math.max(tree[node * 2], tree[node * 2 + 1]); + } + } + + static int querymax(int[] tree, int node, int start, int end, int left, int right) { + if (left > end || right < start) { + return -1; + } + if (left <= start && end <= right) { + return tree[node]; + } + int lmax = querymax(tree, node*2, start, (start+end)/2, left, right); + int rmax = querymax(tree, node*2+1, (start+end)/2+1, end, left, right); + if (lmax == -1) { + return rmax; + } else if (rmax == -1) { + return lmax; + } else { + return Math.max(lmax, rmax); + } + } +} + +``` From 2bf3dc573ee653050dbdda590fd30dd9186d8da0 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Tue, 26 Aug 2025 13:45:49 +0900 Subject: [PATCH 034/143] =?UTF-8?q?[20250826]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EB=82=9C=EB=AF=BC=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../26 BOJ G1 \353\202\234\353\257\274.md" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "Ukj0ng/202508/26 BOJ G1 \353\202\234\353\257\274.md" diff --git "a/Ukj0ng/202508/26 BOJ G1 \353\202\234\353\257\274.md" "b/Ukj0ng/202508/26 BOJ G1 \353\202\234\353\257\274.md" new file mode 100644 index 00000000..bd8a097d --- /dev/null +++ "b/Ukj0ng/202508/26 BOJ G1 \353\202\234\353\257\274.md" @@ -0,0 +1,66 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static PriorityQueue upperQueue; + private static PriorityQueue lowerQueue; + private static int N, median; + private static long sum; + public static void main(String[] args) throws IOException { + init(); + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + long upperVal = 0; + long lowerVal = 0; + median = 0; + sum = 0; + long xSum = 0; + + upperQueue = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[1], o2[1])); + lowerQueue = new PriorityQueue<>((o1, o2) -> Integer.compare(o2[1], o1[1])); + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + + lowerQueue.add(new int[]{x, y}); + lowerVal += y; + xSum += Math.abs(x); + + if (upperQueue.size() + 1 == lowerQueue.size()) { + if (!upperQueue.isEmpty() && upperQueue.peek()[1] < lowerQueue.peek()[1]) { + upperVal += (lowerQueue.peek()[1] - upperQueue.peek()[1]); + lowerVal += (upperQueue.peek()[1] - lowerQueue.peek()[1]); + swap(); + } + } else if (upperQueue.size() + 2 == lowerQueue.size()) { + upperVal += lowerQueue.peek()[1]; + lowerVal -= lowerQueue.peek()[1]; + upperQueue.add(lowerQueue.poll()); + } + + median = lowerQueue.peek()[1]; + long ySum = ((long)median * lowerQueue.size() - lowerVal + upperVal - (long)median * upperQueue.size()); + long totalSum = xSum + ySum; + bw.write(median + " " + totalSum + "\n"); + } + } + + private static void swap() { + int[] temp = lowerQueue.poll(); + lowerQueue.add(upperQueue.poll()); + upperQueue.add(temp); + } +} + +``` From a5e9612f30837acba760f7f74243ce0e07efb338 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 26 Aug 2025 14:26:29 +0900 Subject: [PATCH 035/143] =?UTF-8?q?[20250826]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EB=86=80=EC=9D=B4=20=EA=B3=B5=EC=9B=90=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\264 \352\263\265\354\233\220.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" diff --git "a/suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" "b/suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" new file mode 100644 index 00000000..20e74993 --- /dev/null +++ "b/suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" @@ -0,0 +1,59 @@ +```java +import java.util.*; +import java.io.*; + +public class boj1561 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static long N; + static int M, max = 0; + static int[] time; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + M = nextInt(); + time = new int[M+1]; + nextLine(); + for (int i = 1; i <= M; i++) { + time[i] = nextInt(); + max = Math.max(max, time[i]); + } + if (N <= M) { + System.out.println(N); + return; + } else { + long t = search(); + + long cnt = M; + for (int i = 1; i <= M; i++) + cnt += (t - 1) / time[i]; + + for (int i = 1; i <= M; i++) { + + if (t % time[i] == 0) + cnt++; + + if (cnt == N) { + System.out.println(i); + return; + } + } + } + } + static long search() { + long start = 0; + long end = N/M * max; + while (start <= end) { + long mid = (start + end) / 2; + long sum = M; + for (int i = 1; i <= M; i++) sum += mid / time[i]; + if (sum < N) start = mid + 1; + else end = mid - 1; + } + return start; + } +} +``` From f81f749ec60bbc8a339371e4d4e488159125fbf2 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 26 Aug 2025 17:43:21 +0900 Subject: [PATCH 036/143] =?UTF-8?q?[20250826]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=20=EC=A4=84=EC=9D=B4=EA=B8=B0=20?= =?UTF-8?q?/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\244\204\354\235\264\352\270\260.md" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" diff --git "a/khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" "b/khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" new file mode 100644 index 00000000..40436a5c --- /dev/null +++ "b/khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" @@ -0,0 +1,94 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] a; + static long[][] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + a = new int[N+1]; + for(int i=1;i<=N;i++) a[i] = io.nextInt(); + + dp = new long[N+1][4]; + dp[1][0] = a[1]; + for(int j=1;j<4;j++) dp[1][j] = -(long)1e18; + + for(int i=2;i<=N;i++) { + long xor = 0; + for(int j=0;j<4;j++) { + if(i-j-1 < 0) { + dp[i][j] = -(long)1e18; + continue; + } + xor ^= a[i-j]; + long max = -(long)1e18; + for(int k=0;k<4;k++) if(k != j) max = Math.max(max, dp[i-j-1][k]); + dp[i][j] = max + xor; + } + } + long max = 0; + for(int j=0;j<4;j++) max = Math.max(max, dp[N][j]); + io.write(max + "\n"); + + io.close(); + + } + +} +``` From fcf324ec8316c1db5921e8caaedb338209778dbf Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Tue, 26 Aug 2025 21:36:01 +0900 Subject: [PATCH 037/143] =?UTF-8?q?[20250826]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=ED=87=B4=EC=82=AC2=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202508/26 BOJ \355\207\264\354\202\2542" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "0224LJH/202508/26 BOJ \355\207\264\354\202\2542" diff --git "a/0224LJH/202508/26 BOJ \355\207\264\354\202\2542" "b/0224LJH/202508/26 BOJ \355\207\264\354\202\2542" new file mode 100644 index 00000000..b504201d --- /dev/null +++ "b/0224LJH/202508/26 BOJ \355\207\264\354\202\2542" @@ -0,0 +1,54 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int cnt,ans; + static int[] cost; + static int[] money; + static int[] dp; + + public static void main(String[] args) throws Exception { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cnt = Integer.parseInt(br.readLine()); + cost = new int[cnt+1]; + money = new int[cnt+1]; + dp = new int[cnt+51]; + ans = 0; + for (int i = 1; i <= cnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + cost[i] = Integer.parseInt(st.nextToken()); + money[i] = Integer.parseInt(st.nextToken()); + } + } + + public static void process(){ + for (int i = 1; i <= cnt; i++) { + dp[i] = Math.max(dp[i],dp[i-1]); + if (i + cost[i]-1 > cnt) { + continue; + } + + dp[i + cost[i]-1] = Math.max (dp[i+cost[i]-1] , dp[i-1] + money[i]); + } + + for (int i = 1; i<= cnt; i++) { + System.out.println(dp[i]); + ans = Math.max(ans, dp[i]); + } + } + + public static void print(){ + System.out.println(ans); + } + +``` +} From 3d05a6c2361988f4d0e2b702e27ddd1134d0f67a Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 26 Aug 2025 23:41:56 +0900 Subject: [PATCH 038/143] =?UTF-8?q?[20250826]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../26 BOJ G5 \352\262\214\354\236\204.md" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "lkhyun/202508/26 BOJ G5 \352\262\214\354\236\204.md" diff --git "a/lkhyun/202508/26 BOJ G5 \352\262\214\354\236\204.md" "b/lkhyun/202508/26 BOJ G5 \352\262\214\354\236\204.md" new file mode 100644 index 00000000..8ac6ed46 --- /dev/null +++ "b/lkhyun/202508/26 BOJ G5 \352\262\214\354\236\204.md" @@ -0,0 +1,80 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static int[][] map = new int[501][501]; + static int[][] dist = new int[501][501]; + static int[] dx = {0, 0, -1, 1}; + static int[] dy = {1, -1, 0, 0}; + + public static void main(String[] args) throws IOException { + for (int[] row : dist) Arrays.fill(row, Integer.MAX_VALUE); + + int n = Integer.parseInt(br.readLine()); + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for (int x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) { + for (int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) { + map[x][y] = 1; + } + } + } + + int m = Integer.parseInt(br.readLine()); + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int x1 = Integer.parseInt(st.nextToken()); + int y1 = Integer.parseInt(st.nextToken()); + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + for (int x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) { + for (int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) { + map[x][y] = 2; + } + } + } + + int result = BFS(); + bw.write(String.valueOf(result)); + bw.close(); + } + + private static int BFS() { + ArrayDeque q = new ArrayDeque<>(); + dist[0][0] = 0; + q.add(new int[]{0, 0}); + + while (!q.isEmpty()) { + int[] cur = q.poll(); + int x = cur[0], y = cur[1]; + + for (int i = 0; i < 4; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if (nx < 0 || nx > 500 || ny < 0 || ny > 500 || map[nx][ny] == 2) continue; + + int newDist = dist[x][y] + map[nx][ny]; + if (newDist < dist[nx][ny]) { + dist[nx][ny] = newDist; + if (map[nx][ny] == 0) q.addFirst(new int[]{nx, ny}); + else q.addLast(new int[]{nx, ny}); + } + } + } + + return dist[500][500] == Integer.MAX_VALUE ? -1 : dist[500][500]; + } +} +``` From 3cf675cdbb96dc8122a4c1266d23947de46e1e83 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Tue, 26 Aug 2025 23:58:36 +0900 Subject: [PATCH 039/143] =?UTF-8?q?[20250826]=20BOJ=20/=20G5=20/=201,=202,?= =?UTF-8?q?=203=20=EB=8D=94=ED=95=98=EA=B8=B0=204=20/=20=EC=9D=B4=EC=9D=B8?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\215\224\355\225\230\352\270\260 4.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "LiiNi-coder/202508/26 BOJ 1, 2, 3 \353\215\224\355\225\230\352\270\260 4.md" diff --git "a/LiiNi-coder/202508/26 BOJ 1, 2, 3 \353\215\224\355\225\230\352\270\260 4.md" "b/LiiNi-coder/202508/26 BOJ 1, 2, 3 \353\215\224\355\225\230\352\270\260 4.md" new file mode 100644 index 00000000..142e164d --- /dev/null +++ "b/LiiNi-coder/202508/26 BOJ 1, 2, 3 \353\215\224\355\225\230\352\270\260 4.md" @@ -0,0 +1,55 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + private static BufferedReader br; + private static int t; + private static int n; + private static int[][] dp; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + t = Integer.parseInt(br.readLine()); + int maxN = 10000; + dp = new int[4][maxN + 1]; + dp[1][1] = 1; //1 + dp[1][2] = 1; //1+1 + dp[2][2] = 1; //2 + dp[1][3] = 1; //1+1+1 + dp[2][3] = 1; //2+1 + dp[3][3] = 1; //3 + + for (int i = 1; i <= 3; i++) { + for (int j = 1; j <= maxN; j++) { + dp[0][j] += dp[i][j]; + } + } + + for (int i = 4; i <= maxN; i++) { + //맨 앞 항이 1 -> 1 + (나머지를 1,2,3으로 만듦) + dp[1][i] = dp[0][i - 1]; + + // 맨 앞 항이 2 -> 2 + (나머지를 2,3으로 만듦) + dp[2][i] = dp[2][i - 2] + dp[3][i - 2]; + if (i == 2) dp[2][i] = 1; + + // 맨 앞 항이 3 -> 3 + (나머지를 3으로 만듦) + dp[3][i] = dp[3][i - 3]; + if (i == 3) dp[3][i] = 1; + + dp[0][i] = dp[1][i] + dp[2][i] + dp[3][i]; + } + + StringBuilder sb = new StringBuilder(); + for(int tt = 0; tt Date: Wed, 27 Aug 2025 09:10:21 +0900 Subject: [PATCH 040/143] =?UTF-8?q?[20250827]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=20=ED=95=A9=20=EA=B5=AC=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \352\265\254\355\225\230\352\270\260.md" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "JHLEE325/202508/27 BOJ G1 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.md" diff --git "a/JHLEE325/202508/27 BOJ G1 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.md" "b/JHLEE325/202508/27 BOJ G1 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.md" new file mode 100644 index 00000000..769a5833 --- /dev/null +++ "b/JHLEE325/202508/27 BOJ G1 \352\265\254\352\260\204 \355\225\251 \352\265\254\355\225\230\352\270\260.md" @@ -0,0 +1,85 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + long[] arr = new long[n]; + long[] tree = new long[4*n]; + + for(int i=0;i end || right < start) { + return 0; + } + if (left <= start && end <= right) { + return tree[node]; + } + long lsum = query(tree, node*2, start, (start+end)/2, left, right); + long rsum = query(tree, node*2+1, (start+end)/2+1, end, left, right); + return lsum+rsum; + } + + static void update(long[] arr, long[] tree, int node, int start, int end, int index, long val) { + if (index < start || index > end) { + return; + } + if (start == end) { + arr[index] = val; + tree[node] = val; + return; + } + update(arr, tree,node*2, start, (start+end)/2, index, val); + update(arr, tree,node*2+1, (start+end)/2+1, end, index, val); + tree[node] = tree[node*2] + tree[node*2+1]; + } +} + +``` From f0b19f3897bce2b54891f172f562c7b67ddb6bd8 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Wed, 27 Aug 2025 12:23:19 +0900 Subject: [PATCH 041/143] =?UTF-8?q?[20250827]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EB=B9=84=ED=8A=B8=EC=BD=94=EC=9D=B8=EC=9D=80=20=EC=8B=A0?= =?UTF-8?q?=EC=9D=B4=EA=B3=A0=20=EB=82=98=EB=8A=94=20=EB=AC=B4=EC=A0=81?= =?UTF-8?q?=EC=9D=B4=EB=8B=A4=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\354\240\201\354\235\264\353\213\244.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "Ukj0ng/202508/27 BOJ G3 \353\271\204\355\212\270\354\275\224\354\235\270\354\235\200 \354\213\240\354\235\264\352\263\240 \353\202\230\353\212\224 \353\254\264\354\240\201\354\235\264\353\213\244.md" diff --git "a/Ukj0ng/202508/27 BOJ G3 \353\271\204\355\212\270\354\275\224\354\235\270\354\235\200 \354\213\240\354\235\264\352\263\240 \353\202\230\353\212\224 \353\254\264\354\240\201\354\235\264\353\213\244.md" "b/Ukj0ng/202508/27 BOJ G3 \353\271\204\355\212\270\354\275\224\354\235\270\354\235\200 \354\213\240\354\235\264\352\263\240 \353\202\230\353\212\224 \353\254\264\354\240\201\354\235\264\353\213\244.md" new file mode 100644 index 00000000..4354cc4a --- /dev/null +++ "b/Ukj0ng/202508/27 BOJ G3 \353\271\204\355\212\270\354\275\224\354\235\270\354\235\200 \354\213\240\354\235\264\352\263\240 \353\202\230\353\212\224 \353\254\264\354\240\201\354\235\264\353\213\244.md" @@ -0,0 +1,53 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static TreeSet[] dp; + private static int[] arr; + private static int N, M; + + public static void main(String[] args) throws IOException { + init(); + DP(); + + bw.write(dp[M].last() + "\n"); + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + arr = new int[N + 1]; + dp = new TreeSet[M + 1]; + + for (int i = 0; i <= M; i++) { + dp[i] = new TreeSet<>(); + } + + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + arr[i] = Math.abs(Integer.parseInt(st.nextToken())); + } + } + + private static void DP() { + dp[0].add(0); + for (int i = 1; i <= M; i++) { + for (int j = 1; j <= N; j++) { + for (int val : dp[i - 1]) { + dp[i].add(arr[j] ^ val); + } + } + } + } +} + +``` From 227f340eed7d397c42164cb3b3567d409130d9fa Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 27 Aug 2025 12:45:10 +0900 Subject: [PATCH 042/143] =?UTF-8?q?[20250827]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=EB=8F=84=EB=A1=9C=ED=8F=AC=EC=9E=A5=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\241\234\355\217\254\354\236\245.md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "lkhyun/202508/27 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" diff --git "a/lkhyun/202508/27 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" "b/lkhyun/202508/27 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" new file mode 100644 index 00000000..88897eea --- /dev/null +++ "b/lkhyun/202508/27 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" @@ -0,0 +1,88 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + static int N,M,K; + static class Edge{ + int to,cost; + + Edge(int to, int cost){ + this.to = to; + this.cost = cost; + } + } + static class State{ + int to,k; + long cost; + State(int to, int k, long cost){ + this.to = to; + this.k = k; + this.cost = cost; + } + } + static List[] adjList; + + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + adjList = new ArrayList[N+1]; + + for (int i = 1; i <= N; i++) { + adjList[i] = new ArrayList<>(); + } + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + adjList[from].add(new Edge(to, cost)); + adjList[to].add(new Edge(from, cost)); + } + long[][] dist = dijkstra(); + long ans = Long.MAX_VALUE; + for (int i = 0; i <= K; i++) { + ans = Math.min(ans, dist[N][i]); + } + bw.write(ans+""); + bw.close(); + } + public static long[][] dijkstra(){ + PriorityQueue pq = new PriorityQueue<>((a,b) -> Long.compare(a.cost,b.cost)); + long[][] dist = new long[N+1][K+1]; + for (int i = 1; i <= N; i++) { + Arrays.fill(dist[i],Long.MAX_VALUE); + } + pq.offer(new State(1,0,0)); + dist[1][0] = 0; + + while(!pq.isEmpty()){ + State cur = pq.poll(); + + if(dist[cur.to][cur.k] < cur.cost) continue; + + for(Edge e : adjList[cur.to]){ + long notUsedCost = cur.cost + e.cost; + long usedCost = cur.cost; + + if(notUsedCost < dist[e.to][cur.k]){ + dist[e.to][cur.k] = notUsedCost; + pq.offer(new State(e.to, cur.k, notUsedCost)); + } + + if(cur.k < K && usedCost < dist[e.to][cur.k + 1]){ + dist[e.to][cur.k + 1] = usedCost; + pq.offer(new State(e.to, cur.k + 1, usedCost)); + } + } + } + return dist; + } +} +``` From 7fd4c040d097a877998b93635f8dd773b5356055 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 27 Aug 2025 13:13:29 +0900 Subject: [PATCH 043/143] =?UTF-8?q?[20250827]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EC=97=B0=EC=86=8D=EB=90=9C=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=97=B4=EC=9D=98=20=ED=95=A9=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\227\264\354\235\230 \355\225\251.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" diff --git "a/suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" "b/suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" new file mode 100644 index 00000000..035a31b3 --- /dev/null +++ "b/suyeun84/202508/27 PGM LV2 \354\227\260\354\206\215\353\220\234 \353\266\200\353\266\204 \354\210\230\354\227\264\354\235\230 \355\225\251.md" @@ -0,0 +1,33 @@ +```java +import java.util.*; +class Solution { + public int[] solution(int[] sequence, int k) { + List list = new ArrayList<>(); + int start = 0, end = 0, sum = sequence[0]; + while (start < sequence.length && end < sequence.length) { + if (sum == k) { + list.add(new int[] {start, end}); + } + if (sum <= k) { + end++; + if (end < sequence.length) + sum += sequence[end]; + } else { + if (start < sequence.length) + sum -= sequence[start]; + start++; + } + } + Collections.sort(list, new Comparator() { + @Override + public int compare(int[] o1, int[] o2) { + int len1 = o1[1] - o1[0]; + int len2 = o2[1] - o2[0]; + return len1 - len2; + } + }); + int[] answer = {list.get(0)[0], list.get(0)[1]}; + return answer; + } +} +``` From 06e404eb31201c757cb639c51fe22a72e53b1429 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 27 Aug 2025 15:13:24 +0900 Subject: [PATCH 044/143] =?UTF-8?q?[20250827]=20BOJ=20/=20P3=20/=20?= =?UTF-8?q?=EC=8A=B5=EA=B2=A9=EC=9E=90=20=EC=B4=88=EB=9D=BC=EA=B8=B0=20/?= =?UTF-8?q?=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\264\210\353\235\274\352\270\260.md" | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 "khj20006/202508/27 BOJ P3 \354\212\265\352\262\251\354\236\220 \354\264\210\353\235\274\352\270\260.md" diff --git "a/khj20006/202508/27 BOJ P3 \354\212\265\352\262\251\354\236\220 \354\264\210\353\235\274\352\270\260.md" "b/khj20006/202508/27 BOJ P3 \354\212\265\352\262\251\354\236\220 \354\264\210\353\235\274\352\270\260.md" new file mode 100644 index 00000000..5ac3eb88 --- /dev/null +++ "b/khj20006/202508/27 BOJ P3 \354\212\265\352\262\251\354\236\220 \354\264\210\353\235\274\352\270\260.md" @@ -0,0 +1,122 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + + static int N, W; + static int[][] arr; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + for(int T=io.nextInt();T-->0;) { + N = io.nextInt(); + W = io.nextInt(); + arr = new int[N+1][2]; + for(int i=1;i<=N;i++) arr[i][0] = io.nextInt(); + for(int i=1;i<=N;i++) arr[i][1] = io.nextInt(); + + int ans = Integer.MAX_VALUE; + arr[0][0] = arr[0][1] = INF; + ans = Math.min(ans, get(2)); + arr[0][0] = arr[N][0]; + arr[N][0] = INF; + ans = Math.min(ans, get(1)); + arr[N][0] = arr[0][0]; + arr[0][0] = INF; + arr[0][1] = arr[N][1]; + arr[N][1] = INF; + ans = Math.min(ans, get(0)); + arr[0][0] = arr[N][0]; + arr[N][0] = INF; + for(int i=N;i>=1;i--) { + arr[i][0] = arr[i-1][0]; + arr[i][1] = arr[i-1][1]; + } + arr[0][0] = arr[0][1] = INF; + ans = Math.min(ans, get(2)); + io.write(ans + "\n"); + } + + io.close(); + + } + + static int get(int x) { + int[][] dp = new int[N+1][3]; + if(x == 1) { + dp[0][0] = dp[0][2] = 1; + } + else if(x == 0) { + dp[0][1] = dp[0][2] = 1; + } + + for(int i=1;i<=N;i++) { + dp[i][0] = dp[i-1][2] + 1; + if(arr[i-1][0] + arr[i][0] <= W) dp[i][0] = Math.min(dp[i][0], dp[i-1][1] + 1); + dp[i][1] = dp[i-1][2] + 1; + if(arr[i-1][1] + arr[i][1] <= W) dp[i][1] = Math.min(dp[i][1], dp[i-1][0] + 1); + dp[i][2] = dp[i-1][2] + 2; + if(arr[i-1][0] + arr[i][0] <= W) dp[i][2] = Math.min(dp[i][2], dp[i-1][1] + 2); + if(arr[i-1][1] + arr[i][1] <= W) dp[i][2] = Math.min(dp[i][2], dp[i-1][0] + 2); + if(arr[i-1][0] + arr[i][0] <= W && arr[i-1][1] + arr[i][1] <= W) dp[i][2] = Math.min(dp[i][2], dp[i-2][2] + 2); + if(arr[i][0] + arr[i][1] <= W) dp[i][2] = Math.min(dp[i][2], dp[i-1][2] + 1); + } + return dp[N][x]; + } + +} +``` From 89ed305f033a3c45f42415e3cbcedf2fdb32cf98 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Wed, 27 Aug 2025 17:53:44 +0900 Subject: [PATCH 045/143] =?UTF-8?q?[20250827]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EB=A7=88=EB=9D=BC=ED=86=A4=202=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\247\210\353\235\274\355\206\244 2.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "0224LJH/202508/27 BOJ \353\247\210\353\235\274\355\206\244 2.md" diff --git "a/0224LJH/202508/27 BOJ \353\247\210\353\235\274\355\206\244 2.md" "b/0224LJH/202508/27 BOJ \353\247\210\353\235\274\355\206\244 2.md" new file mode 100644 index 00000000..3352f1ea --- /dev/null +++ "b/0224LJH/202508/27 BOJ \353\247\210\353\235\274\355\206\244 2.md" @@ -0,0 +1,84 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.StringTokenizer; + + +public class Main { + + static int checkCnt, skipMaxCnt,ans; + static int[][] dp; //dp[i][j] skip j번하고 i번째 체크포인트에 도달했을 때의 최댓값 + static int[] y; + static int[] x; + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + checkCnt = Integer.parseInt(st.nextToken()); + skipMaxCnt = Integer.parseInt(st.nextToken()); + dp = new int[checkCnt][skipMaxCnt+1]; + y = new int[checkCnt]; + x = new int[checkCnt]; + + for (int i = 0; i < checkCnt; i++) { + st = new StringTokenizer(br.readLine()); + y[i] = Integer.parseInt(st.nextToken()); + x[i] = Integer.parseInt(st.nextToken()); + + Arrays.fill( dp[i], Integer.MAX_VALUE/2); + } + + + dp[0][0] = 0; + ans = Integer.MAX_VALUE/2; + } + + public static void process() throws IOException { + for (int i = 0; i < checkCnt; i++) { + int curY = y[i]; + int curX = x[i]; + for (int j = 0; j <=skipMaxCnt; j++) { // 이전에 스킵했던 횟수 + for (int k = 0; k <= skipMaxCnt; k++) { // 이번에 스킵하려는 횟수 + int nIdx = i+1+k; + int nSkipCnt = j + k; + + if (nIdx >= checkCnt || nSkipCnt > skipMaxCnt) break; + + int nY = y[nIdx]; + int nX = x[nIdx]; + int plus = Math.abs(curX- nX) + Math.abs(curY - nY); + + dp[nIdx][nSkipCnt] = Math.min(dp[nIdx][nSkipCnt], dp[i][j] + plus); + } + + + + } + } + + for (int i = 0; i <= skipMaxCnt; i++) { + + ans = Math.min(dp[checkCnt-1][i], ans); + } + + } + + + + public static void print() { + System.out.println(ans); + } +} + +``` From fe7b58b7c8fbafd0d4c91f7223fc5300d0f110bf Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Wed, 27 Aug 2025 22:59:27 +0900 Subject: [PATCH 046/143] =?UTF-8?q?[20250827]=20BOJ=20/=20G5=20/=20A?= =?UTF-8?q?=EC=99=80=20B=202=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202508/27 BOJ A\354\231\200 B 2.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "LiiNi-coder/202508/27 BOJ A\354\231\200 B 2.md" diff --git "a/LiiNi-coder/202508/27 BOJ A\354\231\200 B 2.md" "b/LiiNi-coder/202508/27 BOJ A\354\231\200 B 2.md" new file mode 100644 index 00000000..a823518e --- /dev/null +++ "b/LiiNi-coder/202508/27 BOJ A\354\231\200 B 2.md" @@ -0,0 +1,40 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + private static String S, T; + private static boolean isFind = false; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + S = br.readLine(); + T = br.readLine(); + + dfs(T); + System.out.println(isFind ? 1 : 0); + } + + private static void dfs(String cur) { + if (isFind) + return; + if (cur.length() == S.length()) { + if (cur.equals(S)) isFind = true; + return; + } + + // 마지막이 A라면 A 제거 + if (cur.charAt(cur.length() - 1) == 'A') { + dfs(cur.substring(0, cur.length() - 1)); + } + + // 첫 글자가 B라면 B 제거 후 뒤집기 + if (cur.charAt(0) == 'B') { + StringBuilder sb = new StringBuilder(cur.substring(1)); + dfs(sb.reverse().toString()); + } + } +} + +``` From 8c4bd1a89a823f8fb43a27fd664ec7abf8867dd1 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:04:19 +0900 Subject: [PATCH 047/143] =?UTF-8?q?[20250828]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=9D=B4=EB=AA=A8=ED=8B=B0=EC=BD=98=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\252\250\355\213\260\354\275\230.md" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "JHLEE325/202508/28 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" diff --git "a/JHLEE325/202508/28 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" "b/JHLEE325/202508/28 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" new file mode 100644 index 00000000..5b349e04 --- /dev/null +++ "b/JHLEE325/202508/28 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" @@ -0,0 +1,61 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static class State { + int cur, clip; + + State(int cur, int clip) { + this.cur = cur; + this.clip = clip; + } + } + + static int s; + static int range = 2000; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + s = Integer.parseInt(br.readLine()); + System.out.println(bfs()); + } + + static int bfs() { + int[][] dist = new int[range + 1][range + 1]; + for (int i = 0; i <= range; i++) Arrays.fill(dist[i], -1); + + ArrayDeque q = new ArrayDeque<>(); + q.add(new State(1, 0)); + dist[1][0] = 0; + + while (!q.isEmpty()) { + State now = q.poll(); + int cur = now.cur; + int clip = now.clip; + int t = dist[cur][clip]; + + if (cur == s) + return t; + + if (dist[cur][cur] == -1) { + dist[cur][cur] = t + 1; + q.add(new State(cur, cur)); + } + + if (clip > 0 && cur + clip <= range && dist[cur + clip][clip] == -1) { + dist[cur + clip][clip] = t + 1; + q.add(new State(cur + clip, clip)); + } + + if (cur > 0 && dist[cur - 1][clip] == -1) { + dist[cur - 1][clip] = t + 1; + q.add(new State(cur - 1, clip)); + } + } + return -1; + } +} + +``` From a9a6fcd3a2b07d35567081743b5bfc800d0810c8 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:17:27 +0900 Subject: [PATCH 048/143] =?UTF-8?q?[20250828]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=91=90=20=EB=8B=A8=EA=B3=84=20=EC=B5=9C=EB=8B=A8=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=201=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\213\250 \352\262\275\353\241\234 1.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "Ukj0ng/202508/28 BOJ G4 \353\221\220 \353\213\250\352\263\204 \354\265\234\353\213\250 \352\262\275\353\241\234 1.md" diff --git "a/Ukj0ng/202508/28 BOJ G4 \353\221\220 \353\213\250\352\263\204 \354\265\234\353\213\250 \352\262\275\353\241\234 1.md" "b/Ukj0ng/202508/28 BOJ G4 \353\221\220 \353\213\250\352\263\204 \354\265\234\353\213\250 \352\262\275\353\241\234 1.md" new file mode 100644 index 00000000..53ff8c81 --- /dev/null +++ "b/Ukj0ng/202508/28 BOJ G4 \353\221\220 \353\213\250\352\263\204 \354\265\234\353\213\250 \352\262\275\353\241\234 1.md" @@ -0,0 +1,95 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final long INF = (long)2e10 + 10; + private static List[] graph; + private static long[] dist; + private static int N, M, X, Y, Z; + + public static void main(String[] args) throws IOException { + init(); + + dijkstra(X, 0); + long result = dist[Y]; + dijkstra(Y, 0); + result += dist[Z]; + if (result > INF) { + bw.write("-1 "); + } else { + bw.write(result + " "); + } + + dijkstra(X, Y); + if (dist[Z] == INF) { + bw.write("-1 "); + } else { + bw.write(dist[Z] + " "); + } + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + graph = new List[N+1]; + dist = new long[N+1]; + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + + graph[a].add(new Node(b, cost)); + } + + st = new StringTokenizer(br.readLine()); + X = Integer.parseInt(st.nextToken()); + Y = Integer.parseInt(st.nextToken()); + Z = Integer.parseInt(st.nextToken()); + } + + private static void dijkstra(int start, int stopover) { + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> Long.compare(o1.cost, o2.cost)); + Arrays.fill(dist, INF); + dist[start] = 0; + pq.add(new Node(start, 0)); + + while (!pq.isEmpty()) { + Node current = pq.poll(); + + if (current.cost > dist[current.dest]) continue; + + for (Node next : graph[current.dest]) { + if (next.dest == stopover) continue; + if (current.cost + next.cost < dist[next.dest]) { + dist[next.dest] = current.cost + next.cost; + pq.add(new Node(next.dest, dist[next.dest])); + } + } + } + } + + static class Node { + int dest; + long cost; + + Node(int dest, long cost) { + this.dest = dest; + this.cost = cost; + } + } +} +``` From aaa5fa268295ef9e9f5d08b03d9267a3a550ecfc Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 28 Aug 2025 12:09:02 +0900 Subject: [PATCH 049/143] =?UTF-8?q?[20250828]=20BOJ=20/=20P4=20/=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EC=9D=80=20=EB=8B=A4=EC=8B=9C=20=EC=9B=80?= =?UTF-8?q?=EC=A7=81=EC=9D=B8=EB=8B=A4=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\354\247\201\354\235\270\353\213\244.md" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "khj20006/202508/28 BOJ P4 \354\213\234\352\260\204\354\235\200 \353\213\244\354\213\234 \354\233\200\354\247\201\354\235\270\353\213\244.md" diff --git "a/khj20006/202508/28 BOJ P4 \354\213\234\352\260\204\354\235\200 \353\213\244\354\213\234 \354\233\200\354\247\201\354\235\270\353\213\244.md" "b/khj20006/202508/28 BOJ P4 \354\213\234\352\260\204\354\235\200 \353\213\244\354\213\234 \354\233\200\354\247\201\354\235\270\353\213\244.md" new file mode 100644 index 00000000..5656384b --- /dev/null +++ "b/khj20006/202508/28 BOJ P4 \354\213\234\352\260\204\354\235\200 \353\213\244\354\213\234 \354\233\200\354\247\201\354\235\270\353\213\244.md" @@ -0,0 +1,90 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] a; + static boolean[][] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + a = new int[200001]; + for(int i=0;i 1) dp[i][1] = false; + else dp[i][1] = true; + } + for(int t=2;t<450;t++) for(int i=(t-1)*t+t-1;i<=200000;i++) { + if(a[i] - a[i-1] == 0) dp[i][t] = dp[i-1][t]; + if(dp[i-2*t+1][t-1] && (a[i-t]-a[i-2*t+1] == 0)) dp[i][t] = true; + } + for(int t=1;t<450;t++) if(dp[200000][t]) { + io.write("YES"); + io.close(); + return; + } + io.write("NO"); + + io.close(); + + } + +} +``` From ce66bb77bb0ee2f991931539d78d52a6eff9a19b Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Thu, 28 Aug 2025 16:29:31 +0900 Subject: [PATCH 050/143] =?UTF-8?q?[20250828]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EB=AC=B4=EC=9D=B8=EB=8F=84=20=EC=97=AC=ED=96=89=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\217\204 \354\227\254\355\226\211.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "suyeun84/202508/28 PGM LV2 \353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.md" diff --git "a/suyeun84/202508/28 PGM LV2 \353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.md" "b/suyeun84/202508/28 PGM LV2 \353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.md" new file mode 100644 index 00000000..676b9094 --- /dev/null +++ "b/suyeun84/202508/28 PGM LV2 \353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.md" @@ -0,0 +1,50 @@ +```java +import java.util.*; +class Solution { + static int[][] map; + static int N, M; + static int[][] dir = new int[][] {{1,0}, {-1,0}, {0,1}, {0,-1}}; + public int[] solution(String[] maps) { + List sums = new ArrayList<>(); + N = maps.length; + M = maps[0].length(); + map = new int[N][M]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + char temp = maps[i].charAt(j); + if (temp == 'X') map[i][j] = 0; + else map[i][j] = Integer.parseInt(temp+""); + } + } + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (map[i][j] > 0) sums.add(bfs(i, j)); + } + } + if (sums.isEmpty()) return new int[]{-1}; + Collections.sort(sums); + int[] answer = new int[sums.size()]; + for (int i = 0; i < sums.size(); i++) answer[i] = sums.get(i); + return answer; + } + + static int bfs(int y, int x) { + Queue q = new LinkedList<>(); + q.offer(new int[] {y, x}); + int sum = map[y][x]; + map[y][x] = 0; + while (!q.isEmpty()) { + int[] cur = q.poll(); + for (int[] d : dir) { + int ny = cur[0] + d[0]; + int nx = cur[1] + d[1]; + if (ny >= N || ny < 0 || nx >= M || nx < 0 || map[ny][nx] == 0) continue; + q.offer(new int[] {ny, nx}); + sum += map[ny][nx]; + map[ny][nx] = 0; + } + } + return sum; + } +} +``` From abd7ecdc1efba5739e413792d762582e86c40022 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Thu, 28 Aug 2025 16:33:14 +0900 Subject: [PATCH 051/143] =?UTF-8?q?[20250828]=20BOJ=20/=20G2=20/=20?= =?UTF-8?q?=EC=84=B1=EB=83=A5=EA=B0=9C=EB=B9=84=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...61\353\203\245\352\260\234\353\271\204.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "0224LJH/202508/28 BOJ \354\204\261\353\203\245\352\260\234\353\271\204.md" diff --git "a/0224LJH/202508/28 BOJ \354\204\261\353\203\245\352\260\234\353\271\204.md" "b/0224LJH/202508/28 BOJ \354\204\261\353\203\245\352\260\234\353\271\204.md" new file mode 100644 index 00000000..8118230a --- /dev/null +++ "b/0224LJH/202508/28 BOJ \354\204\261\353\203\245\352\260\234\353\271\204.md" @@ -0,0 +1,84 @@ +```java +import java.io.IOException; +import java.math.BigInteger; +import java.io.*; +import java.util.*; + + +public class Main { + + // 1-> 2개 | 2 -> 5개 | 3 -> 5개 | 4개 -> 4개 | 5 -> 5개 | + // 6-> 6개 | 7 -> 3개 | 8 -> 7개 | 9개 -> 6개 | 0 -> 6개 | + + static int[] costs = {6 , 2, 5, 5, 4, 5, 6, 3, 7, 6, 6}; + static BigInteger[] max, min; + + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int cnt = 0; + static final int LARGER = 1; + static final int SMALLER = -1; + + public static void main(String[] args) throws IOException { + int TC = Integer.parseInt(br.readLine()); + + for (int tc = 1; tc <= TC; tc++) { + init(); + process(); + print(); + } + } + + public static void init() throws IOException { + cnt = Integer.parseInt(br.readLine()); + max = new BigInteger[cnt+1]; + min = new BigInteger[cnt+1]; + + for (int i = 0; i <= cnt; i++) max[i] = BigInteger.ZERO; + min[0] = BigInteger.ZERO; + } + + public static void process() throws IOException { + for (int i = 0; i < cnt; i++) { + BigInteger lNum = max[i]; + BigInteger sNum = min[i]; + + + int left = cnt - i; + for (int j = 0; j < 10; j++) { + if (left < costs[j]) continue; + + BigInteger plus = BigInteger.valueOf(j); + BigInteger nLNum = lNum.multiply(BigInteger.valueOf(10)).add(plus); + + + if ( nLNum.compareTo( max[i+costs[j]]) == LARGER) max[i+costs[j]] = nLNum; + } + + if (sNum == null) continue; + + + for (int j = 0; j < 10; j++) { + + + if (sNum == BigInteger.ZERO && j == 0) continue; + if (left < costs[j]) continue; + + BigInteger plus = BigInteger.valueOf(j); + BigInteger nSNum = sNum.multiply(BigInteger.valueOf(10)).add(plus); + + if (min[i+costs[j]] == null + || nSNum.compareTo(min[i+costs[j]]) == SMALLER) min[i+costs[j]] = nSNum; + + } + } + + } + + + + public static void print() { + System.out.println(min[cnt].toString() + " " + max[cnt].toString()); + } +} + +``` From a746cc631cb84162c66ab97d28e38ccaebd15223 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Thu, 28 Aug 2025 23:54:23 +0900 Subject: [PATCH 052/143] =?UTF-8?q?[20250828]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=ED=83=91=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "LiiNi-coder/202508/28 BOJ \355\203\221.md" | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "LiiNi-coder/202508/28 BOJ \355\203\221.md" diff --git "a/LiiNi-coder/202508/28 BOJ \355\203\221.md" "b/LiiNi-coder/202508/28 BOJ \355\203\221.md" new file mode 100644 index 00000000..8051bb1c --- /dev/null +++ "b/LiiNi-coder/202508/28 BOJ \355\203\221.md" @@ -0,0 +1,49 @@ +```java +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.Stack; +import java.util.StringTokenizer; + +public class Main{ + private static BufferedReader Br; + private static int N; + private static int[] Arr; + private static final int MAX = 100_000_001; + private static BufferedWriter Bw; + private static StringBuilder Sb; + + public static void main(String[] args) throws IOException { + Br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(Br.readLine()); + Bw = new BufferedWriter(new OutputStreamWriter(System.out)); + Sb = new StringBuilder(); + Arr = new int[N + 1]; + StringTokenizer st = new StringTokenizer(Br.readLine()); + for(int i = 0; i < N; i++){ + Arr[i+1] = Integer.parseInt(st.nextToken()); + } + + Stack stack = new Stack<>(); + stack.add(new int[]{MAX, 0}); + for (int i = 1; i <= N; i++) { + while (!stack.isEmpty() && stack.peek()[0] < Arr[i]) { + stack.pop(); + } + // stack.peek()[1] == 0 이면, 수신할 탑 없음 + p(stack.peek()[1]); + stack.add(new int[]{Arr[i], i}); + } + Bw.write(Sb.toString() + "\n"); + Bw.flush(); + Bw.close(); + Br.close(); + } + + private static void p(int i){ + Sb.append(i + " "); + } +} +``` From f414e034a63f4b6a0edecdbc961135363252071d Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Fri, 29 Aug 2025 14:25:57 +0900 Subject: [PATCH 053/143] =?UTF-8?q?[20250829]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EA=B3=B5=ED=8F=89=ED=95=98=EA=B2=8C=20=ED=8C=80=20=EB=82=98?= =?UTF-8?q?=EB=88=84=EA=B8=B0=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\202\230\353\210\204\352\270\260.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "JHLEE325/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" diff --git "a/JHLEE325/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" "b/JHLEE325/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" new file mode 100644 index 00000000..8bab3deb --- /dev/null +++ "b/JHLEE325/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" @@ -0,0 +1,54 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int n = Integer.parseInt(br.readLine()); + int[] arr = new int[n]; + int weight_sum = 0; + + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(br.readLine()); + weight_sum += arr[i]; + } + + int member = n / 2; + + boolean[][] weight = new boolean[member + 1][weight_sum + 1]; + + weight[0][0] = true; + + for (int w : arr) { + for (int i = member; i >= 1; i--) { + for (int ws = weight_sum; ws >= 0; ws--) { + if (weight[i - 1][ws]) + weight[i][ws + w] = true; + } + } + } + + int big = 0, small = 0; + int difference = 987654321; + + for (int i = 0; i <= weight_sum; i++) { + if (weight[member][i]) { + int difftemp = Math.abs(weight_sum - (i * 2)); + if (difftemp < difference) { + difference = difftemp; + big = Math.max(weight_sum - i, i); + small = Math.min(weight_sum - i, i); + } + } + } + + System.out.println(small + " " + big); + + } +} + +``` From 05c9045eaffc6066140fd16a584a6dfd4ec41d4d Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Fri, 29 Aug 2025 14:26:47 +0900 Subject: [PATCH 054/143] =?UTF-8?q?[20250829]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EA=B3=B5=ED=8F=89=ED=95=98=EA=B2=8C=20=ED=8C=80=20=EB=82=98?= =?UTF-8?q?=EB=88=84=EA=B8=B0=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \353\202\230\353\210\204\352\270\260.md" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "Ukj0ng/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" diff --git "a/Ukj0ng/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" "b/Ukj0ng/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" new file mode 100644 index 00000000..f4088fed --- /dev/null +++ "b/Ukj0ng/202508/29 BOJ G1 \352\263\265\355\217\211\355\225\230\352\262\214 \355\214\200 \353\202\230\353\210\204\352\270\260.md" @@ -0,0 +1,73 @@ +``` +import java.io.*; +import java.util.HashSet; +import java.util.Set; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static Set[] dp; + private static int[] weight; + private static int N, sum, max; + + public static void main(String[] args) throws IOException { + init(); + DP(); + + int answer = 0; + + for (int val : dp[dp.length-1]) { + answer = Math.max(val, answer); + } + + if (N%2 == 1) { + for (int val : dp[dp.length-2]) { + answer = Math.max(val, answer); + } + } + + bw.write(answer + " " + (sum - answer) + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + sum = 0; + max = 0; + + int length = N/2; + if (N%2 == 1) length++; + weight = new int[N]; + dp = new Set[length + 1]; + for (int i = 0; i < dp.length; i++) { + dp[i] = new HashSet<>(); + } + + dp[0].add(0); + + for (int i = 0; i < N; i++) { + weight[i] = Integer.parseInt(br.readLine()); + sum += weight[i]; + } + + max = sum / 2; + } + + private static void DP() { + for (int i = 0; i < N; i++) { + for (int j = dp.length-1; j > 0; j--) { + if (!dp[j-1].isEmpty()) { + for (int val : dp[j-1]) { + int result = val + weight[i]; + if (result <= max) { + dp[j].add(result); + } + } + } + } + } + } +} +``` From 4eebe0255de309ca74e68f0ae4d86600c7b48981 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 29 Aug 2025 19:25:22 +0900 Subject: [PATCH 055/143] =?UTF-8?q?[20250829]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EC=97=AC=ED=96=89=EA=B2=BD=EB=A1=9C=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\355\226\211\352\262\275\353\241\234.md" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" diff --git "a/suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" "b/suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" new file mode 100644 index 00000000..aae679db --- /dev/null +++ "b/suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" @@ -0,0 +1,35 @@ +``` +import java.util.*; + +class Solution { + static String[][] tickets; + static List answer = new ArrayList<>(); + static int n; + static boolean[] visited; + + public String[] solution(String[][] stickets) { + tickets = stickets; + n = tickets.length; + visited = new boolean[n]; + + dfs(0, "ICN", "ICN"); + Collections.sort(answer); + + return answer.get(0).split(","); + } + public static void dfs(int depth, String start, String path) { + if (depth == n) { + answer.add(path); + return; + } + for (int i = 0; i < tickets.length; i++) { + if (tickets[i][0].equals(start) && !visited[i]) { + visited[i] = true; + dfs(depth+1, tickets[i][1], path + ","+tickets[i][1]); + visited[i] = false; + + } + } + } +} +``` From 5855d3bd7ee3390d70cd8c4cf986681d27d6fc58 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Fri, 29 Aug 2025 20:04:17 +0900 Subject: [PATCH 056/143] =?UTF-8?q?[20250829]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=88=98=EC=98=81=EC=9E=A5=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\245 \353\247\214\353\223\244\352\270\260" | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 "0224LJH/202508/29 BOJ \354\210\230\354\230\201\354\236\245 \353\247\214\353\223\244\352\270\260" diff --git "a/0224LJH/202508/29 BOJ \354\210\230\354\230\201\354\236\245 \353\247\214\353\223\244\352\270\260" "b/0224LJH/202508/29 BOJ \354\210\230\354\230\201\354\236\245 \353\247\214\353\223\244\352\270\260" new file mode 100644 index 00000000..e85487e2 --- /dev/null +++ "b/0224LJH/202508/29 BOJ \354\210\230\354\230\201\354\236\245 \353\247\214\353\223\244\352\270\260" @@ -0,0 +1,116 @@ +```java +import java.awt.Point; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + + +public class Main { + + static boolean[][] visited; + static int[][] arr; + static int[] dy = {-1,0,1,0}; + static int[] dx = {0,1,0,-1}; + + static Queue q = new LinkedList<>(); + static Queue temp = new LinkedList<>(); + + static int height,width,ans; + static boolean isAvailable; + + + + public static void main(String[] args) throws IOException { + + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + height = Integer.parseInt(st.nextToken()); + width = Integer.parseInt(st.nextToken()); + ans = 0; + + arr = new int[height][width]; + visited = new boolean[height][width]; + + for (int i = 0 ; i < height; i++) { + String[] input = br.readLine().split(""); + for (int j = 0; j < width; j++) { + arr[i][j] = Integer.parseInt(input[j]); + System.out.print(arr[i][j]+ " "); + } + System.out.println(); + } + + } + + public static void process() { + for (int water = 2; water <= 9; water++) { + + visited = new boolean[height][width]; + + + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + if (visited[i][j]) continue; + if (arr[i][j] >= water) continue; + + isAvailable = true; + q.clear(); + temp.clear(); + q.add(new Point(j,i)); + temp.add(new Point(j,i)); + bfs(water); + + if (isAvailable) { + while(!temp.isEmpty()) { + Point p = temp.poll(); + + ans += water - arr[p.y][p.x]; + arr[p.y][p.x] = water; + } + } + + } + } + } + + } + + public static void bfs(int water) { + while(!q.isEmpty()) { + Point p = q.poll(); + + for (int i = 0; i < 4; i++) { + int ny = p.y + dy[i]; + int nx = p.x + dx[i]; + + + if (ny < 0 || nx < 0 || ny >= height || nx >= width) { + isAvailable = false; + continue; + } + + if (visited[ny][nx] || arr[ny][nx] >= water) continue; + + visited[ny][nx] = true; + q.add(new Point(nx,ny)); + temp.add(new Point(nx,ny)); + } + } + } + + + + + public static void print() { + System.out.println(ans); + } +} +``` From 4fce021b1057393c32b826ad7823caffea093163 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Fri, 29 Aug 2025 20:26:10 +0900 Subject: [PATCH 057/143] =?UTF-8?q?[20250829]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=83=9D=EC=9D=BC=EC=84=A0=EB=AC=BC=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...35\354\235\274\354\204\240\353\254\274.md" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "lkhyun/202508/29 BOJ G5 \354\203\235\354\235\274\354\204\240\353\254\274.md" diff --git "a/lkhyun/202508/29 BOJ G5 \354\203\235\354\235\274\354\204\240\353\254\274.md" "b/lkhyun/202508/29 BOJ G5 \354\203\235\354\235\274\354\204\240\353\254\274.md" new file mode 100644 index 00000000..c4154455 --- /dev/null +++ "b/lkhyun/202508/29 BOJ G5 \354\203\235\354\235\274\354\204\240\353\254\274.md" @@ -0,0 +1,45 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,D; + static class present{ + int price,value; + + present(int price, int value){ + this.price = price; + this.value = value; + } + } + static present[] arr; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + D = Integer.parseInt(st.nextToken()); + arr = new present[N]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + arr[i] = new present(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())); + } + Arrays.sort(arr,(a,b) -> Integer.compare(a.price,b.price)); + long cur = 0,max = 0; + int left = 0,right = 0; + while(right < N){ + if(arr[right].price - arr[left].price < D){ + cur += arr[right++].value; + max = Math.max(max,cur); + }else{ + cur -= arr[left++].value; + } + } + bw.write(max+""); + bw.close(); + } +} +``` From 5dd075896674a04d6b87638e29de0799ffcd3417 Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 29 Aug 2025 21:47:05 +0900 Subject: [PATCH 058/143] =?UTF-8?q?[20250829]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=EB=B0=94=EB=A6=AC=EC=8A=A4=ED=83=80=EC=9D=98=20=ED=9E=98=20/?= =?UTF-8?q?=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\200\354\235\230 \355\236\230.md" | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 "khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" diff --git "a/khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" "b/khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" new file mode 100644 index 00000000..df893fad --- /dev/null +++ "b/khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" @@ -0,0 +1,135 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + static final int[] dx = {1,0,-1,0}; + static final int[] dy = {0,1,0,-1}; + + static int N, M; + static boolean[][] wall; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + wall = new boolean[N][M]; + for(int i=0;i=0;j--) { + right[i][j] = Math.min(right[i][j+1], to[i][j] + j); + } + } + + int[][] up = new int[N][M]; + for(int j=0;j=0;i--) { + up[i][j] = Math.min(up[i+1][j], to[i][j] + i); + } + } + + int ans = INF; + for(int i=0;i q = new ArrayDeque<>(); + q.offer(new int[]{a,b,0}); + vis[a][b] = true; + while(!q.isEmpty()) { + int[] cur = q.poll(); + int x = cur[0], y = cur[1], t = cur[2]; + res[x][y] = t; + for(int i=0;i<4;i++) { + int xx = x+dx[i], yy = y+dy[i]; + if(xx<0 || xx>=N || yy<0 || yy>=M || vis[xx][yy]) continue; + if(wall[xx][yy]) { + if(can) { + res[xx][yy] = t+1; + vis[xx][yy] = true; + } + continue; + } + q.offer(new int[]{xx,yy,t+1}); + vis[xx][yy] = true; + } + } + return res; + } + +} +``` From f74d26723c5dbfdf5e50580e5b7adb62c84d562b Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 29 Aug 2025 23:31:30 +0900 Subject: [PATCH 059/143] =?UTF-8?q?[20250829]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=ED=83=9D=EB=B0=B0=20=EB=B0=B0=EC=86=A1=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\353\260\260 \353\260\260\354\206\241.md" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "LiiNi-coder/202508/29 BOJ \355\203\235\353\260\260 \353\260\260\354\206\241.md" diff --git "a/LiiNi-coder/202508/29 BOJ \355\203\235\353\260\260 \353\260\260\354\206\241.md" "b/LiiNi-coder/202508/29 BOJ \355\203\235\353\260\260 \353\260\260\354\206\241.md" new file mode 100644 index 00000000..6626977c --- /dev/null +++ "b/LiiNi-coder/202508/29 BOJ \355\203\235\353\260\260 \353\260\260\354\206\241.md" @@ -0,0 +1,80 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static int n; + private static int m; + private static List[] graph; + private static int[] dist; + + private static class Node implements Comparable { + int v; + int w; + + public Node(int v, int w) { + this.v = v; + this.w = w; + } + + @Override + public int compareTo(Node other) { + return this.w - other.w; + } + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + graph = new ArrayList[n + 1]; + for (int i = 1; i <= n; i++) { + graph[i] = new ArrayList<>(); + } + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + graph[a].add(new Node(b, c)); + graph[b].add(new Node(a, c)); + } + + dist = new int[n + 1]; + Arrays.fill(dist, Integer.MAX_VALUE); + + dijkstra(1); + + System.out.println(dist[n]); + } + + private static void dijkstra(int start) { + PriorityQueue pq = new PriorityQueue<>(); + dist[start] = 0; + pq.add(new Node(start, 0)); + + while (!pq.isEmpty()) { + Node now = pq.poll(); + + if (dist[now.v] < now.w) continue; + + for (Node next : graph[now.v]) { + if (dist[next.v] > dist[now.v] + next.w) { + dist[next.v] = dist[now.v] + next.w; + pq.add(new Node(next.v, dist[next.v])); + } + } + } + } +} + +``` From ac3620d91ab58a4c26f181ad8e845cbd88926fe6 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 30 Aug 2025 15:41:51 +0900 Subject: [PATCH 060/143] =?UTF-8?q?[20250830]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EA=B3=A0=EB=83=A5=EC=9D=B4=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\263\240\353\203\245\354\235\264.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "lkhyun/202508/30 BOJ G4 \352\263\240\353\203\245\354\235\264.md" diff --git "a/lkhyun/202508/30 BOJ G4 \352\263\240\353\203\245\354\235\264.md" "b/lkhyun/202508/30 BOJ G4 \352\263\240\353\203\245\354\235\264.md" new file mode 100644 index 00000000..35c7d3e0 --- /dev/null +++ "b/lkhyun/202508/30 BOJ G4 \352\263\240\353\203\245\354\235\264.md" @@ -0,0 +1,42 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static Map cur; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + String str = br.readLine(); + + cur = new HashMap<>(); + + int max = 0; + int ans = 0; + int left = 0, right = 0; + + while(right < str.length()){ + if(cur.size() < N || (cur.size() == N && cur.containsKey(str.charAt(right)))){ + cur.put(str.charAt(right), cur.getOrDefault(str.charAt(right), 0)+1); + ans++; + right++; + max = Math.max(ans,max); + }else{ + ans--; + int temp = cur.get(str.charAt(left)); + if(temp == 1){ + cur.remove(str.charAt(left++)); + }else{ + cur.put(str.charAt(left++), temp-1); + } + } + } + bw.write(max+""); + bw.close(); + } +} +``` From b741708e57e167511918527f08e11ce74df23405 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 30 Aug 2025 16:23:25 +0900 Subject: [PATCH 061/143] =?UTF-8?q?[20250830]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=EB=8F=84=EB=A1=9C=ED=8F=AC=EC=9E=A5=20/=20=ED=95=9C=EC=A2=85?= =?UTF-8?q?=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\241\234\355\217\254\354\236\245.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "Ukj0ng/202508/30 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" diff --git "a/Ukj0ng/202508/30 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" "b/Ukj0ng/202508/30 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" new file mode 100644 index 00000000..77aeff8d --- /dev/null +++ "b/Ukj0ng/202508/30 BOJ P5 \353\217\204\353\241\234\355\217\254\354\236\245.md" @@ -0,0 +1,95 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final long INF = (long) 5e10 + 10; + private static List[] graph; + private static long[][] dist; + private static int N, M, K; + + public static void main(String[] args) throws IOException { + init(); + dijkstra(1); + long answer = INF; + for (int i = 0; i <= K; i++) { + answer = Math.min(answer, dist[N][i]); + } + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + graph = new List[N+1]; + dist = new long[N+1][K+1]; + + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + for (int i = 1; i <= M; i++) { + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + + graph[start].add(new Node(end, cost)); + graph[end].add(new Node(start, cost)); + } + } + + private static void dijkstra(int start) { + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> Long.compare(o1.cost, o2.cost)); + for (int i = 1; i <= N; i++) { + Arrays.fill(dist[i], INF); + } + dist[start][0] = 0; + pq.add(new Node(start, dist[start][0], 0)); + + while (!pq.isEmpty()) { + Node current = pq.poll(); + + if (current.cost > dist[current.dest][current.pavement]) continue; + + for (Node next : graph[current.dest]) { + if (current.pavement+1 <= K && dist[current.dest][current.pavement]< dist[next.dest][current.pavement+1]) { + dist[next.dest][current.pavement+1] = dist[current.dest][current.pavement]; + pq.add(new Node(next.dest, dist[next.dest][current.pavement+1], current.pavement+1)); + } + + if (dist[current.dest][current.pavement] + next.cost < dist[next.dest][current.pavement]) { + dist[next.dest][current.pavement] = dist[current.dest][current.pavement] + next.cost; + pq.add(new Node(next.dest, dist[next.dest][current.pavement], current.pavement)); + } + } + } + } + + static class Node { + int dest; + long cost; + int pavement; + + Node (int dest, long cost) { + this.dest = dest; + this.cost = cost; + this.pavement = 0; + } + + Node (int dest, long cost, int pavement) { + this.dest = dest; + this.cost = cost; + this.pavement = pavement; + } + } +} +``` From 26f8e57257ddc4519859bb0cd84eb3a35205de8e Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 30 Aug 2025 17:44:39 +0900 Subject: [PATCH 062/143] =?UTF-8?q?[20250830]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=8A=A4=EC=B9=B4=EC=9D=B4=EB=9D=BC=EC=9D=B8=20=EC=89=AC?= =?UTF-8?q?=EC=9A=B4=EA=B1=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\211\254\354\232\264\352\261\260.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" diff --git "a/0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" "b/0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" new file mode 100644 index 00000000..cc959a0f --- /dev/null +++ "b/0224LJH/202508/30 BOJ \354\212\244\354\271\264\354\235\264\353\235\274\354\235\270 \354\211\254\354\232\264\352\261\260.md" @@ -0,0 +1,55 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int cnt,ans; + static int[] arr; + + public static void main(String[] args) throws Exception { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cnt = Integer.parseInt(br.readLine()); + arr = new int[cnt]; + for (int i = 0; i < cnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + st.nextToken(); + arr[i] = Integer.parseInt(st.nextToken()); + } + ans = 0; + } + + public static void process(){ + PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); + for (int i = 0; i < cnt; i++) { + int height = arr[i]; + + while (!pq.isEmpty() && pq.peek() > height) { + pq.poll(); + ans++; + } + + if (height == 0) continue; + + if (pq.isEmpty() || pq.peek() != height) pq.add(height); + + + } + + ans += pq.size(); + } + + public static void print(){ + System.out.println(ans); + } + + +} +``` From 6ae806d39575d9f33344e07098a9512d9cfc102a Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 30 Aug 2025 17:51:23 +0900 Subject: [PATCH 063/143] =?UTF-8?q?[20250830]=20BOJ=20/=20P4=20/=20?= =?UTF-8?q?=EB=B6=80=EB=AA=A8=EB=8B=98=EA=BB=98=20=ED=81=B0=EC=A0=88=20?= =?UTF-8?q?=ED=95=98=EA=B3=A0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\240\210 \355\225\230\352\263\240.md" | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 "khj20006/202508/30 BOJ P4 \353\266\200\353\252\250\353\213\230\352\273\230 \355\201\260\354\240\210 \355\225\230\352\263\240.md" diff --git "a/khj20006/202508/30 BOJ P4 \353\266\200\353\252\250\353\213\230\352\273\230 \355\201\260\354\240\210 \355\225\230\352\263\240.md" "b/khj20006/202508/30 BOJ P4 \353\266\200\353\252\250\353\213\230\352\273\230 \355\201\260\354\240\210 \355\225\230\352\263\240.md" new file mode 100644 index 00000000..4a2e7ab7 --- /dev/null +++ "b/khj20006/202508/30 BOJ P4 \353\266\200\353\252\250\353\213\230\352\273\230 \355\201\260\354\240\210 \355\225\230\352\263\240.md" @@ -0,0 +1,121 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] a; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + a = new int[N]; + int min = Integer.MAX_VALUE; + for(int i=0;i list = new ArrayList<>(); + for(int i=2;i Date: Sat, 30 Aug 2025 23:12:58 +0900 Subject: [PATCH 064/143] =?UTF-8?q?[20250830]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EC=9E=85=EA=B5=AD=EC=8B=AC=EC=82=AC=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...05\352\265\255\354\213\254\354\202\254.md" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "suyeun84/202508/30 PGM LV3 \354\236\205\352\265\255\354\213\254\354\202\254.md" diff --git "a/suyeun84/202508/30 PGM LV3 \354\236\205\352\265\255\354\213\254\354\202\254.md" "b/suyeun84/202508/30 PGM LV3 \354\236\205\352\265\255\354\213\254\354\202\254.md" new file mode 100644 index 00000000..c7b0e6cd --- /dev/null +++ "b/suyeun84/202508/30 PGM LV3 \354\236\205\352\265\255\354\213\254\354\202\254.md" @@ -0,0 +1,23 @@ +```java +import java.util.*; +class Solution { + public long solution(int n, int[] times) { + Arrays.sort(times); + long start = 0; + long end = (long)times[times.length-1]*(long)n; + while (start <= end) { + long mid = (start + end) / 2; + long total = 0; + for (int i = 0; i < times.length; i++) { + total += mid / times[i]; + } + if (total < n) { + start = mid + 1; + } else { + end = mid - 1; + } + } + return start; + } +} +``` From 88b09217928a63c5a43d226e8dc1d3b8ca4efc12 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sat, 30 Aug 2025 23:44:53 +0900 Subject: [PATCH 065/143] =?UTF-8?q?[20250830]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=B0=84=EC=84=A0=20=EC=9D=B4=EC=96=B4=EA=B0=80=EA=B8=B0=202?= =?UTF-8?q?=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\226\264\352\260\200\352\270\260 2.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "LiiNi-coder/202508/30 BOJ \352\260\204\354\204\240 \354\235\264\354\226\264\352\260\200\352\270\260 2.md" diff --git "a/LiiNi-coder/202508/30 BOJ \352\260\204\354\204\240 \354\235\264\354\226\264\352\260\200\352\270\260 2.md" "b/LiiNi-coder/202508/30 BOJ \352\260\204\354\204\240 \354\235\264\354\226\264\352\260\200\352\270\260 2.md" new file mode 100644 index 00000000..1e2d2307 --- /dev/null +++ "b/LiiNi-coder/202508/30 BOJ \352\260\204\354\204\240 \354\235\264\354\226\264\352\260\200\352\270\260 2.md" @@ -0,0 +1,81 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.PriorityQueue; +import java.util.StringTokenizer; +import java.util.Arrays; + +public class Main { + private static BufferedReader br; + private static int n, m; + private static List[] graph; + private static int[] dist; + + private static class Node implements Comparable { + int v; + int w; + + public Node(int v, int w) { + this.v = v; + this.w = w; + } + + @Override + public int compareTo(Node o) { + return this.w - o.w; + } + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + graph = new ArrayList[n + 1]; + for (int i = 1; i <= n; i++) { + graph[i] = new ArrayList<>(); + } + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + graph[a].add(new Node(b, c)); + graph[b].add(new Node(a, c)); + } + st = new StringTokenizer(br.readLine()); + int s = Integer.parseInt(st.nextToken()); + int t = Integer.parseInt(st.nextToken()); + + dist = new int[n + 1]; + Arrays.fill(dist, Integer.MAX_VALUE); + + dijkstra(s); + System.out.println(dist[t]); + } + + private static void dijkstra(int start) { + PriorityQueue pq = new PriorityQueue<>(); + dist[start] = 0; + pq.add(new Node(start, 0)); + + while (!pq.isEmpty()) { + Node cur = pq.poll(); + int v = cur.v; + int w = cur.w; + if (dist[v] < w) + continue; + for (Node next : graph[v]) { + if (dist[next.v] > dist[v] + next.w) { + dist[next.v] = dist[v] + next.w; + pq.add(new Node(next.v, dist[next.v])); + } + } + } + } +} + +``` From b48c7cfcae755dab1409350b0057dc46915ac168 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sun, 31 Aug 2025 12:21:30 +0900 Subject: [PATCH 066/143] =?UTF-8?q?[20250831]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=B9=84=EC=8A=B7=ED=95=9C=20=EB=8B=A8=EC=96=B4=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7\355\225\234 \353\213\250\354\226\264.md" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "0224LJH/202508/31 BOJ \353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.md" diff --git "a/0224LJH/202508/31 BOJ \353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.md" "b/0224LJH/202508/31 BOJ \353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.md" new file mode 100644 index 00000000..b949e206 --- /dev/null +++ "b/0224LJH/202508/31 BOJ \353\271\204\354\212\267\355\225\234 \353\213\250\354\226\264.md" @@ -0,0 +1,91 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int size,ansIdx, longest=0; + static String ans1,ans2; + static String[] words; + + static class TrieNode{ + Map children = new HashMap<>(); + String word; + int num; + boolean isWord; + + public TrieNode(String word, int num){ + this.word = word; + this.num = num; + } + } + + static void insert(String nWord, int wordNum){ + TrieNode node = root; + int len = 0; + int tempIdx = 0; + boolean isEnd = false; + String tempWord = ""; + + for (int i = 0; i < nWord.length(); i++){ + Character c = nWord.charAt(i); + if (node.children.containsKey(c)){ + node = node.children.get(c); + if (!isEnd){ + len++; + tempWord = node.word; + tempIdx = node.num; + } + } else { + node.children.put(c, new TrieNode(nWord,wordNum)); + node = node.children.get(c); + isEnd = true; + } + } + + if (longest < len || (longest == len && tempIdx < ansIdx )){ + ansIdx = tempIdx; + longest = len; + ans1 = tempWord; + ans2 = nWord; + } + } + + static TrieNode root = new TrieNode("",-1); + + public static void main(String[] args) throws Exception { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + size =Integer.parseInt(br.readLine()); + words = new String[size]; + ansIdx = -1; + for (int i = 0; i < size; i++) { + words[i] = br.readLine(); + + } + } + + public static void process(){ + for(int i = 0; i < size; i++){ + insert(words[i],i); +// System.out.println("longest = " + longest); +// System.out.println("ans1 = " + ans1); +// System.out.println("ans2 = " + ans2); + } + } + + public static void print(){ + System.out.println(longest); + System.out.println(ans1); + System.out.println(ans2); + } + + +} +``` From 98b57d4c9b49318b95b006afb4266157193ce856 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sun, 31 Aug 2025 13:20:52 +0900 Subject: [PATCH 067/143] =?UTF-8?q?[20250831]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=EA=B0=99=EC=9D=80=20=ED=83=91=20/=20=ED=95=9C=EC=A2=85?= =?UTF-8?q?=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \352\260\231\354\235\200 \355\203\221.md" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "Ukj0ng/202508/31 BOJ P5 \352\260\231\354\235\200 \355\203\221.md" diff --git "a/Ukj0ng/202508/31 BOJ P5 \352\260\231\354\235\200 \355\203\221.md" "b/Ukj0ng/202508/31 BOJ P5 \352\260\231\354\235\200 \355\203\221.md" new file mode 100644 index 00000000..7fdf2f77 --- /dev/null +++ "b/Ukj0ng/202508/31 BOJ P5 \352\260\231\354\235\200 \355\203\221.md" @@ -0,0 +1,63 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[] block, dp; + private static int N, sum; + + public static void main(String[] args) throws IOException { + init(); + DP(); + + int answer = dp[0] > 0 ? dp[0] : -1; + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + sum = 0; + + block = new int[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + block[i] = Integer.parseInt(st.nextToken()); + sum += block[i]; + } + + dp = new int[sum + 1]; + Arrays.fill(dp, -1); + dp[0] = 0; + } + + private static void DP() { + for (int i = 0; i < N; i++) { + int[] newDp = dp.clone(); + + for (int j = 0; j <= sum; j++) { + if (dp[j] == -1) continue; + + int higher = dp[j]; + int lower = higher - j; + + newDp[j + block[i]] = Math.max(newDp[j + block[i]], higher + block[i]); + + int newLower = lower + block[i]; + if (newLower > higher) { + newDp[newLower - higher] = Math.max(newDp[newLower - higher], newLower); + } else { + newDp[higher - newLower] = Math.max(newDp[higher - newLower], higher); + } + } + + dp = newDp; + } + } +} +``` From fef0520b1ea998e8cfbecae82f67c8b7bb37bfb6 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sun, 31 Aug 2025 14:40:50 +0900 Subject: [PATCH 068/143] =?UTF-8?q?[20250831]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=B9=98=ED=82=A8=20=EB=B0=B0=EB=8B=AC=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\202\250 \353\260\260\353\213\254.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "JHLEE325/202508/31 BOJ G5 \354\271\230\355\202\250 \353\260\260\353\213\254.md" diff --git "a/JHLEE325/202508/31 BOJ G5 \354\271\230\355\202\250 \353\260\260\353\213\254.md" "b/JHLEE325/202508/31 BOJ G5 \354\271\230\355\202\250 \353\260\260\353\213\254.md" new file mode 100644 index 00000000..4e29be02 --- /dev/null +++ "b/JHLEE325/202508/31 BOJ G5 \354\271\230\355\202\250 \353\260\260\353\213\254.md" @@ -0,0 +1,69 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int n, m, h, c; + static List houses = new ArrayList<>(); + static List chickens = new ArrayList<>(); + static int[][] dist; + static int[] pick; + static int answer = Integer.MAX_VALUE; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < n; j++) { + int v = Integer.parseInt(st.nextToken()); + if (v == 1) houses.add(new int[]{i, j}); + else if (v == 2) chickens.add(new int[]{i, j}); + } + } + + h = houses.size(); + c = chickens.size(); + + dist = new int[h][c]; + for (int h = 0; h < Main.h; h++) { + int hx = houses.get(h)[0], hy = houses.get(h)[1]; + for (int k = 0; k < Main.c; k++) { + int cx = chickens.get(k)[0], cy = chickens.get(k)[1]; + dist[h][k] = Math.abs(hx - cx) + Math.abs(hy - cy); + } + } + + pick = new int[m]; + dfs(0, 0); + + System.out.println(answer); + } + + static void dfs(int start, int depth) { + if (depth == m) { + int sum = 0; + for (int h = 0; h < Main.h; h++) { + int best = Integer.MAX_VALUE; + for (int p = 0; p < m; p++) { + best = Math.min(best, dist[h][pick[p]]); + } + sum += best; + if (sum >= answer) return; + } + answer = Math.min(answer, sum); + return; + } + + for (int i = start; i < c; i++) { + pick[depth] = i; + dfs(i + 1, depth + 1); + } + } +} + +``` From 8fe0c35d00933f8ca77a3b1750d8ea49c9cfb996 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 31 Aug 2025 20:17:25 +0900 Subject: [PATCH 069/143] =?UTF-8?q?[20250831]=20BOJ=20/=20D5=20/=20?= =?UTF-8?q?=EA=B7=B8=EB=9E=98=ED=94=84=EC=99=80=20=EC=BF=BC=EB=A6=AC=20/?= =?UTF-8?q?=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\231\200 \354\277\274\353\246\254.md" | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 "khj20006/202508/31 BOJ D5 \352\267\270\353\236\230\355\224\204\354\231\200 \354\277\274\353\246\254.md" diff --git "a/khj20006/202508/31 BOJ D5 \352\267\270\353\236\230\355\224\204\354\231\200 \354\277\274\353\246\254.md" "b/khj20006/202508/31 BOJ D5 \352\267\270\353\236\230\355\224\204\354\231\200 \354\277\274\353\246\254.md" new file mode 100644 index 00000000..9285e590 --- /dev/null +++ "b/khj20006/202508/31 BOJ D5 \352\267\270\353\236\230\355\224\204\354\231\200 \354\277\274\353\246\254.md" @@ -0,0 +1,184 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +class DisjointSet { + int size; + int[] root, rank; + Stack works; + + DisjointSet(int size) { + this.size = size; + root = new int[size+1]; + rank = new int[size+1]; + for(int i=1;i<=size;i++) { + root[i] = i; + rank[i] = 1; + } + works = new Stack<>(); + } + + int find(int x) { return x == root[x] ? x : find(root[x]); } + + void union(int a, int b) { + int x = find(a), y = find(b); + if(x == y) { + works.push(new int[]{-1,-1,-1}); + return; + } + if(rank[x] < rank[y]) { + rank[y] += rank[x]; + root[x] = y; + works.add(new int[]{x, y, rank[x]}); + } + else { + rank[x] += rank[y]; + root[y] = x; + works.add(new int[]{y, x, rank[y]}); + } + } + + void rollback() { + if (!works.isEmpty()) { + int[] last = works.pop(); + int x = last[0], y = last[1], r = last[2]; + if(x == -1) return; + rank[y] -= r; + root[x] = x; + } + } + +} + +public class Main { + + static IOController io; + + // + + static int N, M; + static List[] lists; + static DisjointSet ds; + static List[] needAnswer; + + static void update(int s, int e, int l, int r, int n, int a, int b) { + if(l>r || l>e || r>1; + update(s,m,l,r,n*2,a,b); + update(m+1,e,l,r,n*2+1,a,b); + } + + static void clear(int s, int e, int n) throws Exception { + for(int[] edge : lists[n]) { + int a = edge[0], b = edge[1]; + ds.union(a,b); + } + if(s == e) { + for(int[] info : needAnswer[s]) { + int a = info[0], b = info[1]; + if(ds.find(a) == ds.find(b)) io.write("1\n"); + else io.write("0\n"); + } + for(int i=0;i>1; + clear(s,m,n*2); + clear(m+1,e,n*2+1); + for(int i=0;i(); + ds = new DisjointSet(N); + needAnswer = new List[M]; + for(int i=0;i(); + Map map = new TreeMap<>(); + for(int i=0;i b) { + int t = a; + a = b; + b = t; + } + if(op == 1) map.put(a+","+b, i); + else if(op == 2) { + update(0,M-1,map.get(a+","+b),i,1,a,b); + map.remove(a+","+b); + } + else { + needAnswer[i].add(new int[]{a,b}); + } + } + for(String key : map.keySet()) { + String[] words = key.split(","); + int a = Integer.parseInt(words[0]); + int b = Integer.parseInt(words[1]); + update(0,M-1,map.get(key),M,1,a,b); + } + + clear(0,M-1,1); + + io.close(); + + } + +} +``` From 8a5f09e1b5be5a856ce1bdecfe0d02501b2cc4ad Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:41:18 +0900 Subject: [PATCH 070/143] =?UTF-8?q?[20250831]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=B0=9C=EB=98=A5=EB=B2=8C=EB=A0=88=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\230\245\353\262\214\353\240\210.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" diff --git "a/lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" "b/lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" new file mode 100644 index 00000000..ae806384 --- /dev/null +++ "b/lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" @@ -0,0 +1,50 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,H; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + H = Integer.parseInt(st.nextToken()); + + int[] top = new int[H+1]; + int[] bot = new int[H+1]; + for (int i = 0; i < N; i++) { + int cur = Integer.parseInt(br.readLine()); + if(i%2 == 0){ + bot[cur]++; + }else{ + top[cur]++; + } + } + + for (int i = H-1; i > 1; i--) { + bot[i-1] += bot[i]; + } + for (int i = H-1; i > 1; i--) { + top[i-1] += top[i]; + } + + int min = N; + int cnt = 0; + for (int i = 1; i <= H; i++) { + int cur = top[H-i+1] + bot[i]; + if(min == cur){ + cnt++; + }else if(min > cur){ + min = cur; + cnt = 1; + } + } + + bw.write(min+" "+cnt); + bw.close(); + } +} +``` From 22a8d7bc7ac0d84b1bbe8f6117508f7d0e3a25ee Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sun, 31 Aug 2025 23:00:53 +0900 Subject: [PATCH 071/143] =?UTF-8?q?[20250831]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EB=93=B1=EA=B5=A3=EA=B8=B8=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3 \353\223\261\352\265\243\352\270\270.md" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "suyeun84/202508/31 PGM LV3 \353\223\261\352\265\243\352\270\270.md" diff --git "a/suyeun84/202508/31 PGM LV3 \353\223\261\352\265\243\352\270\270.md" "b/suyeun84/202508/31 PGM LV3 \353\223\261\352\265\243\352\270\270.md" new file mode 100644 index 00000000..3927b6cb --- /dev/null +++ "b/suyeun84/202508/31 PGM LV3 \353\223\261\352\265\243\352\270\270.md" @@ -0,0 +1,26 @@ +```java +class Solution { + public int solution(int m, int n, int[][] puddles) { + int answer = 0; + int[][] dp = new int[n+1][m+1]; + dp[1][1] = 1; + for (int[] temp : puddles) { + dp[temp[1]][temp[0]] = -1; + } + for (int i = 1; i < n+1; i++) { + for (int j = 1; j < m+1; j++) { + if (i == 1 && j == 1) continue; + if (dp[i][j] == -1) continue; + + if (dp[i][j-1] > 0) { + dp[i][j] = (dp[i][j] + dp[i][j-1]) % 1000000007; + } + if (dp[i-1][j] > 0) { + dp[i][j] = (dp[i][j] + dp[i-1][j]) % 1000000007; + } + } + } + return dp[n][m]; + } +} +``` From f6aeb255f10961dca62c1e11409d73191e1be9ea Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sun, 31 Aug 2025 23:52:09 +0900 Subject: [PATCH 072/143] =?UTF-8?q?[20250831]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=85=B8=EB=93=9C=EC=82=AC=EC=9D=B4=EC=9D=98=20=EA=B1=B0?= =?UTF-8?q?=EB=A6=AC=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \352\261\260\353\246\254.md" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "LiiNi-coder/202508/31 BOJ \353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.md" diff --git "a/LiiNi-coder/202508/31 BOJ \353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.md" "b/LiiNi-coder/202508/31 BOJ \353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.md" new file mode 100644 index 00000000..7a451142 --- /dev/null +++ "b/LiiNi-coder/202508/31 BOJ \353\205\270\353\223\234\354\202\254\354\235\264\354\235\230 \352\261\260\353\246\254.md" @@ -0,0 +1,87 @@ +```java +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader Br; + private static BufferedWriter Bw; + private static StringBuilder Sb; + private static int N; + private static int M; + private static List[] Graph; + + private static class Node implements Comparable { + int v; + int w; + public Node(int v, int w) { + this.v = v; + this.w = w; + } + @Override + public int compareTo(Node o) { + return this.w - o.w; + } + } + + public static void main(String[] args) throws IOException { + Br = new BufferedReader(new InputStreamReader(System.in)); + Bw = new BufferedWriter(new OutputStreamWriter(System.out)); + Sb = new StringBuilder(); + StringTokenizer st = new StringTokenizer(Br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + Graph = new ArrayList[N + 1]; + for (int i = 1; i <= N; i++) { + Graph[i] = new ArrayList<>(); + } + for (int i = 0; i < N - 1; i++) { + st = new StringTokenizer(Br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + Graph[a].add(new Node(b, w)); + Graph[b].add(new Node(a, w)); + } + for (int i = 0; i < M; i++) { + st = new StringTokenizer(Br.readLine()); + int s = Integer.parseInt(st.nextToken()); + int e = Integer.parseInt(st.nextToken()); + Sb.append(dijkstra(s, e)).append("\n"); + } + Bw.write(Sb.toString()); + Bw.flush(); + Bw.close(); + Br.close(); + } + + private static int dijkstra(int start, int end) { + int[] dist = new int[N + 1]; + for (int i = 1; i <= N; i++) + dist[i] = Integer.MAX_VALUE; + PriorityQueue pq = new PriorityQueue<>(); + pq.add(new Node(start, 0)); + dist[start] = 0; + while (!pq.isEmpty()) { + Node cur = pq.poll(); + if (dist[cur.v] < cur.w) continue; + if (cur.v == end) return cur.w; + + for (Node next : Graph[cur.v]) { + if (dist[next.v] > cur.w + next.w) { + dist[next.v] = cur.w + next.w; + pq.add(new Node(next.v, dist[next.v])); + } + } + } + return -1; + } +} + +``` From e2271bcf27f75afdf3732bdf497837edda26953c Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Mon, 1 Sep 2025 08:12:55 +0900 Subject: [PATCH 073/143] =?UTF-8?q?[20250901]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=B4=84=ED=98=B8=EC=9D=98=20=EA=B0=92=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\230\270\354\235\230 \352\260\222.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "JHLEE325/202509/01 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" diff --git "a/JHLEE325/202509/01 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" "b/JHLEE325/202509/01 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" new file mode 100644 index 00000000..e09ce74e --- /dev/null +++ "b/JHLEE325/202509/01 BOJ G5 \352\264\204\355\230\270\354\235\230 \352\260\222.md" @@ -0,0 +1,81 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String str = br.readLine(); + + Stack stack = new Stack<>(); + Stack values = new Stack<>(); + + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + + if (c == '(' || c == '[') { + stack.push(c); + values.push(-1); + } else { + if (stack.isEmpty()) { + System.out.println(0); + return; + } + + if (c == ')') { + if (stack.peek() != '(') { + System.out.println(0); + return; + } + stack.pop(); + + int sum = 0; + while (!values.isEmpty() && values.peek() != -1) { + sum += values.pop(); + } + if (values.isEmpty() || values.peek() != -1) { + System.out.println(0); + return; + } + values.pop(); + values.push(sum == 0 ? 2 : sum * 2); + } else if (c == ']') { + if (stack.peek() != '[') { + System.out.println(0); + return; + } + stack.pop(); + + int sum = 0; + while (!values.isEmpty() && values.peek() != -1) { + sum += values.pop(); + } + if (values.isEmpty() || values.peek() != -1) { + System.out.println(0); + return; + } + values.pop(); + values.push(sum == 0 ? 3 : sum * 3); + } + } + } + + if (!stack.isEmpty()) { + System.out.println(0); + return; + } + + int result = 0; + while (!values.isEmpty()) { + if (values.peek() == -1) { + System.out.println(0); + return; + } + result += values.pop(); + } + + System.out.println(result); + } +} + +``` From 8372955b0b0a1101cc1b3da799fc7553793e316a Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:40:51 +0900 Subject: [PATCH 074/143] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bd5bce54..dd5ce135 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,11 @@ - - - - - + + + + +

Solved.ac 프로필

Solved.ac 프로필

Solved.ac 프로필

Solved.ac 프로필
이강현
8월 제출8월 제출8월 제출8월 제출8월 제출9월 제출9월 제출9월 제출9월 제출9월 제출
@@ -50,9 +50,9 @@ 이인희 - 8월 제출 - 8월 제출 - 8월 제출 + 9월 제출 + 9월 제출 + 9월 제출
From ec56e1667b1f1e78f15580e5e0d217887596b5d3 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:42:16 +0900 Subject: [PATCH 075/143] =?UTF-8?q?[20250901]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EC=9C=A1=EA=B0=81=20=EB=B3=B4=EB=93=9C/=20=ED=95=9C=EC=A2=85?= =?UTF-8?q?=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\352\260\201 \353\263\264\353\223\234.md" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" diff --git "a/Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" "b/Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" new file mode 100644 index 00000000..ec33577e --- /dev/null +++ "b/Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" @@ -0,0 +1,71 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final int[] dx = {1, 1, 0, 0, -1, -1}; + private static final int[] dy = {0, -1, 1, -1, 0, 1}; + private static char[][] board; + private static int[][] arr; + private static int N, color; + + public static void main(String[] args) throws IOException { + init(); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (board[i][j] == 'X' && arr[i][j] == 0) { + color = Math.max(color, 1); + BFS(i, j); + } + } + } + + bw.write(color + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + color = 0; + board = new char[N][N]; + arr = new int[N][N]; + + for (int i = 0; i < N; i++) { + board[i] = br.readLine().toCharArray(); + } + } + + private static void BFS(int x, int y) { + Queue q = new ArrayDeque<>(); + arr[x][y] = 1; + q.add(new int[]{x, y}); + + while (!q.isEmpty()) { + int[] current = q.poll(); + + for (int i = 0; i < 6; i++) { + int nx = current[0] + dx[i]; + int ny = current[1] + dy[i]; + + if (OOB(nx, ny) || board[nx][ny] != 'X') continue; + if (arr[nx][ny] == 0) { + color = Math.max(color, 2); + arr[nx][ny] = 3 - arr[current[0]][current[1]]; + q.add(new int[]{nx, ny}); + } else if (arr[nx][ny] == arr[current[0]][current[1]]) { + color = Math.max(color, 3); + return; + } + } + } + } + + private static boolean OOB(int nx, int ny) { + return nx < 0 || nx > N-1 || ny < 0 || ny > N-1; + } +} +``` From 8cb957e44dcd8444ae97b1e645d780766b2d57b6 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:58:43 +0900 Subject: [PATCH 076/143] =?UTF-8?q?[20250901]=20BOJ=20/=20G3=20/=200=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EA=B8=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...OJ 0 \353\247\214\353\223\244\352\270\260" | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 "0224LJH/202509/01 BOJ 0 \353\247\214\353\223\244\352\270\260" diff --git "a/0224LJH/202509/01 BOJ 0 \353\247\214\353\223\244\352\270\260" "b/0224LJH/202509/01 BOJ 0 \353\247\214\353\223\244\352\270\260" new file mode 100644 index 00000000..32107bb6 --- /dev/null +++ "b/0224LJH/202509/01 BOJ 0 \353\247\214\353\223\244\352\270\260" @@ -0,0 +1,119 @@ +```java +import java.io.IOException; +import java.math.BigInteger; +import java.io.*; +import java.util.*; + + +public class Main { + + static int cnt,target,ans; + static int[] arr; + static List list; + static String[] decide; + static StringBuilder sb = new StringBuilder(); + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cnt = Integer.parseInt(br.readLine()); + arr = new int[cnt]; + + + for (int i = 0; i < cnt; i++) { + arr[i] = Integer.parseInt(br.readLine()); + } + } + + public static void process() throws IOException { + for (int tc = 0; tc < cnt; tc++) { + ans = 0; + target = arr[tc]; + decide = new String[target]; + list = new ArrayList<>(); + list.add(1); + + dfs(1); + + if (ans != 0) sb.append("\n"); + } + } + + public static void dfs(int num) { + if (num == target) { + + calculate(); + + return; + } + + + int nNum = num+1; + int temp = list.get(list.size()-1); + + + list.remove(list.size()-1); + decide[num-1] = " "; + + if (temp < 0) { + list.add(temp*10 - num - 1); + } else { + list.add(temp*10 + num + 1); + } + + dfs(num+1); + list.remove(list.size()-1); + list.add(temp); + + + + list.add(num+1); + decide[num-1] = "+"; + dfs(num+1); + list.remove(list.size()-1); + + list.add((num+1)*(-1)); + decide[num-1] = "-"; + dfs(num+1); + list.remove(list.size()-1); + + + + + + + + } + + public static void calculate() { + int res = 0; + + for (int n: list) { + res += n; + } + + if (res == 0) { + ans++; + sb.append(1); + for (int i = 1; i < target; i++) { + sb.append(decide[i-1]).append(i+1); + } + sb.append("\n"); + } + } + + + + public static void print() { + System.out.println(sb.toString()); + } +} + +``` From 1bb93f0001185540eacc6d9a696253c662109223 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 1 Sep 2025 22:06:27 +0900 Subject: [PATCH 077/143] =?UTF-8?q?[20250901]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EA=BF=80=20=EB=94=B0=EA=B8=B0=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \352\277\200 \353\224\260\352\270\260.md" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "lkhyun/202509/01 BOJ G5 \352\277\200 \353\224\260\352\270\260.md" diff --git "a/lkhyun/202509/01 BOJ G5 \352\277\200 \353\224\260\352\270\260.md" "b/lkhyun/202509/01 BOJ G5 \352\277\200 \353\224\260\352\270\260.md" new file mode 100644 index 00000000..7ba3c50f --- /dev/null +++ "b/lkhyun/202509/01 BOJ G5 \352\277\200 \353\224\260\352\270\260.md" @@ -0,0 +1,67 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static int[] original; + static long[] leftSum; + static long[] rightSum; + static long total; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + + original = new int[N]; + leftSum = new long[N]; + rightSum = new long[N]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + original[i] = Integer.parseInt(st.nextToken()); + } + + // 왼쪽에서 오른쪽으로 + leftSum[0] = original[0]; + for (int i = 1; i < N; i++) { + leftSum[i] = leftSum[i-1] + original[i]; + } + + // 오른쪽에서 왼쪽으로 + rightSum[N-1] = original[N-1]; + for (int i = N-2; i >= 0; i--) { + rightSum[i] = rightSum[i+1] + original[i]; + } + + total = leftSum[N-1]; + long max = 0; + + //벌통이 맨 오른쪽, 벌1이 맨 왼쪽 고정, 벌2 위치 선택 + for (int i = 1; i < N-1; i++) { + long bee1 = total - original[0] - original[i]; + long bee2 = total - leftSum[i]; + max = Math.max(max, bee1 + bee2); + } + + //벌통이 맨 왼쪽, 벌1이 맨 오른쪽 고정, 벌2 위치 선택 + for (int i = N-2; i > 0; i--) { + long bee1 = total - original[N-1] - original[i]; + long bee2 = total - rightSum[i]; + max = Math.max(max, bee1 + bee2); + } + + //벌1이 맨 왼쪽, 벌2가 맨 오른쪽 고정, 벌통 위치 선택 + for (int i = 1; i < N-1; i++) { + long bee1 = leftSum[i] - original[0]; + long bee2 = rightSum[i] - original[N-1]; + max = Math.max(max, bee1 + bee2); + } + + bw.write(max + ""); + bw.close(); + } +} +``` From 098564be9b075212dcc150977c11ffb825ae193e Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 1 Sep 2025 22:34:05 +0900 Subject: [PATCH 078/143] =?UTF-8?q?[20250901]=20BOJ=20/=20P3=20/=20?= =?UTF-8?q?=EC=8B=9D=EB=8B=B9=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../01 BOJ P3 \354\213\235\353\213\271.md" | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 "khj20006/202509/01 BOJ P3 \354\213\235\353\213\271.md" diff --git "a/khj20006/202509/01 BOJ P3 \354\213\235\353\213\271.md" "b/khj20006/202509/01 BOJ P3 \354\213\235\353\213\271.md" new file mode 100644 index 00000000..98f3cde3 --- /dev/null +++ "b/khj20006/202509/01 BOJ P3 \354\213\235\353\213\271.md" @@ -0,0 +1,102 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + + static int N, M; + static int[] a; + static int[][] dp, idx; + static int[] min; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + a = new int[N+1]; + for(int i=1;i<=N;i++) a[i] = io.nextInt(); + dp = new int[N+1][201]; + idx = new int[N+1][201]; + min = new int[N+1]; + Arrays.fill(min, INF); + min[0] = 0; + + for(int k=1;k<=200;k++) { + int[] cnt = new int[M+1]; + int count = 0; + for(int s=1,e=1;e<=N;e++) { + if(cnt[a[e]]++ == 0) count++; + while(count > k) { + if(--cnt[a[s++]] == 0) count--; + } + + idx[e][k] = s; + } + } + + for(int i=1;i<=N;i++) { + for(int k=1;k<=200;k++) dp[i][k] = min[idx[i][k]-1] + k*k; + for(int k=1;k<=200;k++) min[i] = Math.min(min[i], dp[i][k]); + } + + io.write(min[N] + "\n"); + + io.close(); + + } + +} +``` From 98a7be2bf0bfc8b2e105f138c01fdf797219538b Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 1 Sep 2025 23:06:08 +0900 Subject: [PATCH 079/143] =?UTF-8?q?[20250901]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EB=B6=80=EB=8C=80=EB=B3=B5=EA=B7=80=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\353\214\200\353\263\265\352\267\200.md" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "suyeun84/202509/01 PGM LV3 \353\266\200\353\214\200\353\263\265\352\267\200.md" diff --git "a/suyeun84/202509/01 PGM LV3 \353\266\200\353\214\200\353\263\265\352\267\200.md" "b/suyeun84/202509/01 PGM LV3 \353\266\200\353\214\200\353\263\265\352\267\200.md" new file mode 100644 index 00000000..d2ba27ea --- /dev/null +++ "b/suyeun84/202509/01 PGM LV3 \353\266\200\353\214\200\353\263\265\352\267\200.md" @@ -0,0 +1,45 @@ +```java +import java.util.*; +class Solution { + int[] answer; + int[] result; + List graph[]; + + public int[] solution(int n, int[][] roads, int[] sources, int destination) { + answer = new int[n+1]; + result = new int[sources.length]; + graph = new ArrayList[n+1]; + Arrays.fill(answer, -1); + + for (int i = 0; i < n+1; i++) { + graph[i] = new ArrayList<>(); + } + + for (int[] road : roads) { + graph[road[0]].add(road[1]); + graph[road[1]].add(road[0]); + } + + bfs(destination); + + for (int i = 0; i < sources.length; i++) { + result[i] = answer[sources[i]]; + } + return result; + } + public void bfs(int start) { + Queue q = new ArrayDeque<>(); + q.add(start); + answer[start] = 0; + while (!q.isEmpty()) { + int curr = q.poll(); + for (int next : graph[curr]) { + if (answer[next] == -1) { + answer[next] = answer[curr] + 1; + q.add(next); + } + } + } + } +} +``` From d2e558128ae298bce836adb9eb25b4f7eac945ab Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Mon, 1 Sep 2025 23:36:16 +0900 Subject: [PATCH 080/143] =?UTF-8?q?[20250901]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EC=9B=9C=ED=99=80=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../01 BOJ \354\233\234\355\231\200.md" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "LiiNi-coder/202509/01 BOJ \354\233\234\355\231\200.md" diff --git "a/LiiNi-coder/202509/01 BOJ \354\233\234\355\231\200.md" "b/LiiNi-coder/202509/01 BOJ \354\233\234\355\231\200.md" new file mode 100644 index 00000000..fc4c134a --- /dev/null +++ "b/LiiNi-coder/202509/01 BOJ \354\233\234\355\231\200.md" @@ -0,0 +1,83 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static StringBuilder sb; + private static StringTokenizer st; + private static int n; + private static int m; + private static int w; + private static class Edge { + int from; + int to; + int weight; + public Edge(int from, int to, int weight) { + this.from = from; + this.to = to; + this.weight = weight; + } + } + + private static ArrayList edges; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + sb = new StringBuilder(); + + int tc = Integer.parseInt(br.readLine()); + while (tc-- > 0) { + st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + w = Integer.parseInt(st.nextToken()); + + edges = new ArrayList<>(); + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int s = Integer.parseInt(st.nextToken()); + int e = Integer.parseInt(st.nextToken()); + int t = Integer.parseInt(st.nextToken()); + edges.add(new Edge(s, e, t)); + edges.add(new Edge(e, s, t)); + } + + for (int i = 0; i < w; i++) { + st = new StringTokenizer(br.readLine()); + int s = Integer.parseInt(st.nextToken()); + int e = Integer.parseInt(st.nextToken()); + int t = Integer.parseInt(st.nextToken()); + edges.add(new Edge(s, e, -t)); + } + if (bellmanFord()) { + sb.append("YES\n"); + } else { + sb.append("NO\n"); + } + } + + System.out.print(sb.toString()); + } + + private static boolean bellmanFord() { + int[] dist = new int[n + 1]; + for (int i = 1; i < n; i++) { + for (Edge edge : edges) { + if (dist[edge.to] > dist[edge.from] + edge.weight) { + dist[edge.to] = dist[edge.from] + edge.weight; + } + } + } + for (Edge edge : edges) { + if (dist[edge.to] > dist[edge.from] + edge.weight) { + return true; + } + } + return false; + } +} +``` From 5ba70d67ea1ee0d01f25cb55f613a4b4a919b637 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Tue, 2 Sep 2025 09:20:41 +0900 Subject: [PATCH 081/143] =?UTF-8?q?[20250902]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=BA=A0=ED=94=84=20=EC=A4=80=EB=B9=84=20/=20=ED=95=9C?= =?UTF-8?q?=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\355\224\204 \354\244\200\353\271\204.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "Ukj0ng/202509/2 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" diff --git "a/Ukj0ng/202509/2 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" "b/Ukj0ng/202509/2 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" new file mode 100644 index 00000000..e2489c1a --- /dev/null +++ "b/Ukj0ng/202509/2 BOJ G5 \354\272\240\355\224\204 \354\244\200\353\271\204.md" @@ -0,0 +1,62 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[] arr, combination, temp; + private static int N, L, R, X, answer; + + public static void main(String[] args) throws IOException { + init(); + for (int i = 2; i <= N; i++) { + combination = new int[i]; + temp = new int[i]; + dfs(0, 0); + } + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + L = Integer.parseInt(st.nextToken()); + R = Integer.parseInt(st.nextToken()); + X = Integer.parseInt(st.nextToken()); + answer = 0; + + arr = new int[N]; + st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + } + + private static void dfs(int start, int index) { + if (index == combination.length) { + int[] clone = combination.clone(); + Arrays.sort(clone); + int sum = Arrays.stream(clone).sum(); + if (sum < L) return; + if (sum > R) return; + if (clone[clone.length-1] - clone[0] < X) return; + answer++; + return; + } + + for (int i = start; i < N; i++) { + combination[index] = arr[i]; + temp[index] = i; + dfs(i+1, index+1); + } + } +} + +``` From 3cad0cb58ea9049179f52c0350e0f5c04855d435 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Tue, 2 Sep 2025 10:51:08 +0900 Subject: [PATCH 082/143] =?UTF-8?q?[20250902]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=A0=84=EA=B9=83=EC=A4=84=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5 \354\240\204\352\271\203\354\244\204.md" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "JHLEE325/202509/02 BOJ G5 \354\240\204\352\271\203\354\244\204.md" diff --git "a/JHLEE325/202509/02 BOJ G5 \354\240\204\352\271\203\354\244\204.md" "b/JHLEE325/202509/02 BOJ G5 \354\240\204\352\271\203\354\244\204.md" new file mode 100644 index 00000000..58bec3c7 --- /dev/null +++ "b/JHLEE325/202509/02 BOJ G5 \354\240\204\352\271\203\354\244\204.md" @@ -0,0 +1,45 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int n = Integer.parseInt(br.readLine()); + int[][] elec = new int[n][2]; + int[] dp = new int[n]; + + for(int i=0;i{ + return o1[0]-o2[0]; + }); + + for(int i=0;ielec[j][1]){ + dp[i] = Math.max(dp[i],dp[j]+1); + } + } + } + + int result = 0; + for(int i=0;i Date: Tue, 2 Sep 2025 13:22:19 +0900 Subject: [PATCH 083/143] =?UTF-8?q?[20250902]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EB=AF=B8=EC=B9=9C=20=EC=95=84=EB=91=90=EC=9D=B4=EB=85=B8=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\221\220\354\235\264\353\205\270.md" | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 "0224LJH/202509/02 BOJ \353\257\270\354\271\234 \354\225\204\353\221\220\354\235\264\353\205\270.md" diff --git "a/0224LJH/202509/02 BOJ \353\257\270\354\271\234 \354\225\204\353\221\220\354\235\264\353\205\270.md" "b/0224LJH/202509/02 BOJ \353\257\270\354\271\234 \354\225\204\353\221\220\354\235\264\353\205\270.md" new file mode 100644 index 00000000..d12d9e73 --- /dev/null +++ "b/0224LJH/202509/02 BOJ \353\257\270\354\271\234 \354\225\204\353\221\220\354\235\264\353\205\270.md" @@ -0,0 +1,152 @@ +```java +import java.io.IOException; +import java.math.BigInteger; +import java.awt.Point; +import java.io.*; +import java.util.*; + + +public class Main { + + static int height,width,len,nTargetY,nTargetX,res; + + static int[] dy = {0,1,1,1,0,0,0,-1,-1,-1}; + static int[] dx = {0,-1,0,1,-1,0,1,-1,0,1}; + static int[] dir; + + static Point target; + static Queue arduinos; + static Arduino[][] visited; + static StringBuilder sb = new StringBuilder(); + + static class Arduino{ + Point p; + boolean isOkay; + + public Arduino (int x, int y){ + p = new Point(x,y); + isOkay = true; + } + + } + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + height = Integer.parseInt(st.nextToken()); + width = Integer.parseInt(st.nextToken()); + arduinos = new LinkedList<>(); + + for (int i = 0; i < height; i++) { + String[] input = br.readLine().split(""); + for (int j = 0; j < width; j++) { + String temp = input[j]; + + if (temp.equals("I")) target = new Point(j,i); + else if (temp.equals("R")) arduinos.add(new Arduino(j,i)); + } + } + + String[] rawNum = br.readLine().split(""); + len = rawNum.length; + dir = new int[len]; + for (int i = 0; i < len; i++) dir[i] = Integer.parseInt(rawNum[i]); + + } + + public static void process() throws IOException { + + res = -1; // -1이 유지되면 끝까지 이동한것. + + for (int i = 0; i < len; i++) { + visited = new Arduino [height][width]; + nTargetY = target.y + dy[dir[i]]; + nTargetX = target.x + dx[dir[i]]; + + target = new Point(nTargetX,nTargetY); + + processEach(i+1); + + if (res != -1) break; + + } + + + makeAns(); + } + + + + private static void processEach(int round) { + int qSize = arduinos.size(); + + for (int j = 0 ; j < qSize; j++) { + Arduino a = arduinos.poll(); + + if (!a.isOkay) continue; + + int ny = a.p.y; + int nx = a.p.x; + + if (a.p.y != nTargetY) ny += a.p.y < nTargetY?(1):(-1); + if (a.p.x != nTargetX) nx += a.p.x < nTargetX?(1):(-1); + + a.p.y = ny; + a.p.x = nx; + + if (ny == nTargetY && nx == nTargetX) { + res = round; + break; + } + + if (visited[ny][nx] == null) { + visited[ny][nx] = a; + arduinos.add(a); + } else { + visited[ny][nx].isOkay = false; + } + } + } + + private static void makeAns() { + if (res != -1) { + sb.append("kraj ").append(res).append("\n"); + return; + } + + String[][] ansArr = new String[height][width]; + + for (int i = 0; i < height; i++) Arrays.fill(ansArr[i], "."); + + ansArr[target.y][target.x] = "I"; + + while(!arduinos.isEmpty()) { + Arduino a = arduinos.poll(); + if (!a.isOkay) continue; + + ansArr[a.p.y][a.p.x] = "R"; + } + + for (int i = 0; i < height; i++) { + for (int j = 0; j Date: Tue, 2 Sep 2025 21:55:14 +0900 Subject: [PATCH 084/143] =?UTF-8?q?[20250902]=20BOJ=20/=20P3=20/=20?= =?UTF-8?q?=EC=95=88=EC=95=84=EC=A4=98=EC=9A=94=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...10\354\225\204\354\244\230\354\232\224.md" | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 "khj20006/202509/02 BOJ P3 \354\225\210\354\225\204\354\244\230\354\232\224.md" diff --git "a/khj20006/202509/02 BOJ P3 \354\225\210\354\225\204\354\244\230\354\232\224.md" "b/khj20006/202509/02 BOJ P3 \354\225\210\354\225\204\354\244\230\354\232\224.md" new file mode 100644 index 00000000..a94d6795 --- /dev/null +++ "b/khj20006/202509/02 BOJ P3 \354\225\210\354\225\204\354\244\230\354\232\224.md" @@ -0,0 +1,149 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +class SegTree { + int[] tree; + SegTree(int size) { + tree = new int[size*4]; + } + + void update(int s, int e, int i, int v, int n) { + if(s == e) { + tree[n] = Math.max(tree[n], v); + return; + } + int m = (s+e)>>1; + if(i <= m) update(s,m,i,v,n*2); + else update(m+1,e,i,v,n*2+1); + tree[n] = Math.max(tree[n*2],tree[n*2+1]); + } + + int find(int s, int e, int l, int r, int n) { + if(l>r || l>e || r>1; + return Math.max(find(s,m,l,r,n*2), find(m+1,e,l,r,n*2+1)); + } +} + +public class Main { + + static IOController io; + + // + + static int N, Q; + static int[][] points; + static SegTree seg1, seg2; + + static int index(List arr, int x) { + int s = 0, e = arr.size(), m = (s+e)>>1; + while(s>1; + } + return m; + } + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + Q = io.nextInt(); + points = new int[N][]; + List list1 = new ArrayList<>(); + List list2 = new ArrayList<>(); + for(int i=0;i arr1 = new ArrayList<>(); + List arr2 = new ArrayList<>(); + arr1.add(list1.get(0)); + for(int i=1;i a[1]==b[1] ? a[0]-b[0] : a[1]-b[1]); + for(int i=0;i update1 = new ArrayList<>(); + List update2 = new ArrayList<>(); + while(i0) io.write(ans[io.nextInt()] + "\n"); + + io.close(); + + } + +} +``` From 566be64c43232e3260f4462421c54711f39c9394 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 2 Sep 2025 23:30:30 +0900 Subject: [PATCH 085/143] =?UTF-8?q?[20250902]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EC=A7=95=EA=B2=80=EB=8B=A4=EB=A6=AC=20=EA=B1=B4=EB=84=88?= =?UTF-8?q?=EA=B8=B0=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\261\264\353\204\210\352\270\260.md" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "suyeun84/202509/02 PGM LV3 \354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.md" diff --git "a/suyeun84/202509/02 PGM LV3 \354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.md" "b/suyeun84/202509/02 PGM LV3 \354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.md" new file mode 100644 index 00000000..10f4a27c --- /dev/null +++ "b/suyeun84/202509/02 PGM LV3 \354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.md" @@ -0,0 +1,32 @@ +```java +import java.util.*; +class Solution { + public int solution(int[] stones, int k) { + int answer = Integer.MIN_VALUE; + int start = 0; + int end = 200000000; + while (start <= end) { + int mid = (start + end) / 2; + int cnt = 0; + boolean flag = true; + for (int i = 0; i < stones.length; i++) { + if (stones[i] - mid < 0) { + cnt++; + } else { + cnt = 0; + } + if (cnt >= k) { + end = mid - 1; + flag = false; + break; + } + } + if (flag == true) { + answer = start; + start = mid + 1; + } + } + return end; + } +} +``` From f9205b89e843d7e86c8dd0ffc2d7284de97c4183 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 2 Sep 2025 23:35:28 +0900 Subject: [PATCH 086/143] =?UTF-8?q?[20250902]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=8F=99=EC=A0=84=202=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../02 BOJ G5 \353\217\231\354\240\204 2.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "lkhyun/202509/02 BOJ G5 \353\217\231\354\240\204 2.md" diff --git "a/lkhyun/202509/02 BOJ G5 \353\217\231\354\240\204 2.md" "b/lkhyun/202509/02 BOJ G5 \353\217\231\354\240\204 2.md" new file mode 100644 index 00000000..0621842d --- /dev/null +++ "b/lkhyun/202509/02 BOJ G5 \353\217\231\354\240\204 2.md" @@ -0,0 +1,38 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,K; + static Set coins; + static int[] dp; //dp[i]: i원을 만드는데 필요한 동전의 최소 개수 + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + coins = new HashSet<>(); + dp = new int[K+1]; + for (int i = 0; i < N; i++) { + coins.add(Integer.parseInt(br.readLine())); + } + + Arrays.fill(dp,Integer.MAX_VALUE); + dp[0] = 0; + + for (int i : coins) { + for (int j = i; j <= K; j++) { + if(dp[j-i] != Integer.MAX_VALUE){ + dp[j] = Math.min(dp[j],dp[j-i]+1); + } + } + } + int ans = dp[K] == Integer.MAX_VALUE ? -1 : dp[K]; + + bw.write(ans + ""); + bw.close(); + } +} +``` From 6803761514e46bb546690c19c4a26537f161bec1 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Tue, 2 Sep 2025 23:47:11 +0900 Subject: [PATCH 087/143] =?UTF-8?q?[20250902]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EB=82=98=EB=A7=8C=20=EC=95=88=EB=90=98=EB=8A=94=20=EC=97=B0?= =?UTF-8?q?=EC=95=A0=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\212\224 \354\227\260\354\225\240.md" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "LiiNi-coder/202509/02 BOJ \353\202\230\353\247\214 \354\225\210\353\220\230\353\212\224 \354\227\260\354\225\240.md" diff --git "a/LiiNi-coder/202509/02 BOJ \353\202\230\353\247\214 \354\225\210\353\220\230\353\212\224 \354\227\260\354\225\240.md" "b/LiiNi-coder/202509/02 BOJ \353\202\230\353\247\214 \354\225\210\353\220\230\353\212\224 \354\227\260\354\225\240.md" new file mode 100644 index 00000000..bfe66962 --- /dev/null +++ "b/LiiNi-coder/202509/02 BOJ \353\202\230\353\247\214 \354\225\210\353\220\230\353\212\224 \354\227\260\354\225\240.md" @@ -0,0 +1,90 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static int n; + private static int m; + private static char[] genders; + private static ArrayList[] graph; + + private static class Edge implements Comparable { + int v; + int w; + public Edge(int v, int w) { + this.v = v; + this.w = w; + } + @Override + public int compareTo(Edge o) { + return this.w - o.w; + } + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + genders = new char[n + 1]; + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= n; i++) { + genders[i] = st.nextToken().charAt(0); + } + graph = new ArrayList[n + 1]; + for (int i = 1; i <= n; i++) { + graph[i] = new ArrayList<>(); + } + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int u = Integer.parseInt(st.nextToken()); + int v = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + //같은 성별 노드는 연결하지 않음 + if (genders[u] == genders[v]) continue; + graph[u].add(new Edge(v, w)); + graph[v].add(new Edge(u, w)); + } + + int answer = prim(); + System.out.println(answer); + } + + private static int prim() { + boolean[] visited = new boolean[n + 1]; + PriorityQueue pq = new PriorityQueue<>(); + int total = 0; + int count = 0; + visited[1] = true; + count++; + for (Edge e : graph[1]) { + pq.add(e); + } + + while (!pq.isEmpty()) { + Edge cur = pq.poll(); + if (visited[cur.v]) continue; + visited[cur.v] = true; + total += cur.w; + count++; + for (Edge next : graph[cur.v]) { + if (!visited[next.v]) { + pq.add(next); + } + } + } + + if (count == n) { + return total; + } else { + return -1; + } + } +} + +``` From 4d0fb7aac524512393f1e9c2df75cfd87e2e3483 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Wed, 3 Sep 2025 07:56:13 +0900 Subject: [PATCH 088/143] =?UTF-8?q?[20250903]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=ED=87=B4=EC=82=AC=202=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../03 BOJ G5 \355\207\264\354\202\254 2.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "JHLEE325/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" diff --git "a/JHLEE325/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" "b/JHLEE325/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" new file mode 100644 index 00000000..26767b4c --- /dev/null +++ "b/JHLEE325/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" @@ -0,0 +1,38 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int n = Integer.parseInt(br.readLine()); + + int[][] arr =new int[n+2][2]; + int[] dp = new int[n+2]; + for(int i=1; i Date: Wed, 3 Sep 2025 10:43:20 +0900 Subject: [PATCH 089/143] =?UTF-8?q?[20250903]=20BOJ=20/=20G1=20/=20K-?= =?UTF-8?q?=EC=A7=80=ED=8F=90=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3 BOJ G1 K-\354\247\200\355\217\220.md" | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 "Ukj0ng/202509/3 BOJ G1 K-\354\247\200\355\217\220.md" diff --git "a/Ukj0ng/202509/3 BOJ G1 K-\354\247\200\355\217\220.md" "b/Ukj0ng/202509/3 BOJ G1 K-\354\247\200\355\217\220.md" new file mode 100644 index 00000000..438eacdd --- /dev/null +++ "b/Ukj0ng/202509/3 BOJ G1 K-\354\247\200\355\217\220.md" @@ -0,0 +1,99 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final long INF = (long) 1e15 + 10; + private static List[] graph; + private static long[][] dist; + private static int N, M, K, S, T; + + public static void main(String[] args) throws IOException { + init(); + dijkstra(S); + + long answer = -1; + if (dist[T][0] != INF) { + answer = dist[T][0]; + } + + if (answer == -1) bw.write("IMPOSSIBLE" + "\n"); + else bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + S = Integer.parseInt(st.nextToken()); + T = Integer.parseInt(st.nextToken()); + + graph = new List[N + 1]; + dist = new long[N + 1][K]; + + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + long cost = Long.parseLong(st.nextToken()); + + graph[a].add(new Edge(b, cost)); + } + } + + private static void dijkstra(int start) { + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> Long.compare(o1.cost, o2.cost)); + for (int i = 1; i <= N; i++) { + Arrays.fill(dist[i], INF); + } + dist[start][0] = 0; + pq.add(new Edge(start, 0, 0)); + + while (!pq.isEmpty()) { + Edge current = pq.poll(); + + if (current.cost > dist[current.dest][current.state]) continue; + + for (Edge next : graph[current.dest]) { + long nCost = current.cost + next.cost; + int nState = (int) (nCost % K); + + if (nCost < dist[next.dest][nState]) { + dist[next.dest][nState] = nCost; + pq.add(new Edge(next.dest, dist[next.dest][nState], nState)); + } + } + } + } + + static class Edge { + int dest; + long cost; + int state; + + public Edge(int dest, long cost, int state) { + this.dest = dest; + this.cost = cost; + this.state = state; + } + + public Edge(int dest, long cost) { + this.dest = dest; + this.cost = cost; + this.state = 0; + } + } +} +``` From 92b664876125d88104a187ca6276d436dfaf5fc4 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 3 Sep 2025 16:15:43 +0900 Subject: [PATCH 090/143] =?UTF-8?q?[20250903]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=ED=87=B4=EC=82=AC=202=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../03 BOJ G5 \355\207\264\354\202\254 2.md" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "lkhyun/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" diff --git "a/lkhyun/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" "b/lkhyun/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" new file mode 100644 index 00000000..8ed8fc6f --- /dev/null +++ "b/lkhyun/202509/03 BOJ G5 \355\207\264\354\202\254 2.md" @@ -0,0 +1,44 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static int[] time; + static int[] reward; + static int[] dp; + + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + time = new int[N+1]; + reward = new int[N+1]; + dp = new int[N+2]; + + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + int t = Integer.parseInt(st.nextToken()); + int r = Integer.parseInt(st.nextToken()); + time[i] = t; + reward[i] = r; + } + + int ans = 0; + for (int i = 1; i <= N; i++) { + dp[i] = Math.max(dp[i],dp[i-1]); + int cur = i+time[i]; + if(cur<=N+1){ + dp[cur] = Math.max(dp[cur],dp[i] + reward[i]); + } + + } + for (int i = 1; i <= N+1; i++) { + ans = Math.max(ans,dp[i]); + } + bw.write(ans+""); + bw.close(); + } +} +``` From 27d330e3c30f4a4872290280a8a6e4aecb3b151d Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 3 Sep 2025 21:11:23 +0900 Subject: [PATCH 091/143] =?UTF-8?q?[20250903]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EB=94=94=EC=8A=A4=ED=81=AC=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...50\355\212\270\353\241\244\353\237\254.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "suyeun84/202509/03 PGM LV3 \353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.md" diff --git "a/suyeun84/202509/03 PGM LV3 \353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.md" "b/suyeun84/202509/03 PGM LV3 \353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.md" new file mode 100644 index 00000000..b246e634 --- /dev/null +++ "b/suyeun84/202509/03 PGM LV3 \353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.md" @@ -0,0 +1,29 @@ + '''java +import java.util.*; +class Solution { + public int solution(int[][] jobs) { + int answer = 0; + jobs.add(new int[]{1, 1}); + Arrays.sort(jobs, (o1, o2) -> Integer.compare(o1[0], o2[0])); + PriorityQueue pq = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[0], o2[0])); + int curr_time = 0; + int curr_idx = 0; + int cnt = 0; + while (cnt < jobs.length) { + while (curr_idx < jobs.length && jobs[curr_idx][0] <= curr_time) { + pq.add(new int[]{jobs[curr_idx][1], jobs[curr_idx][0]}); //(걸리는 시간, 시작 시간) + curr_idx += 1; + } + if (!pq.isEmpty()) { + int[] time = pq.poll(); + cnt += 1; + answer += (curr_time - time[1] + time[0]); + curr_time += time[0]; + } else { + curr_time += 1; + } + } + return answer / jobs.length; + } +} +``` From fe6fcf757efd602273ed15f98c8fdf9636e5a3a3 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Wed, 3 Sep 2025 22:00:05 +0900 Subject: [PATCH 092/143] =?UTF-8?q?[20250903]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=EB=84=B7=20=EC=84=A4=EC=B9=98=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\260\353\204\267 \354\204\244\354\271\230" | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 "0224LJH/202509/03 BOJ \354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230" diff --git "a/0224LJH/202509/03 BOJ \354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230" "b/0224LJH/202509/03 BOJ \354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230" new file mode 100644 index 00000000..633f03a3 --- /dev/null +++ "b/0224LJH/202509/03 BOJ \354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230" @@ -0,0 +1,161 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + + + static Node[] nodes; + static boolean[] visited; + static int[] totalCost; + + static boolean canReach = false; + static int nodeCnt, edgeCnt, freeCnt,ans; + + static PriorityQueue nodePq = new PriorityQueue<>();; + + static class Node implements Comparable{ + int num; + HashMap to = new HashMap<>(); + + public void addEdge(int nodeNum, int cost) { + Node n = nodes[nodeNum]; + + if (!to.containsKey(nodeNum)) { + to.put(nodeNum, cost); + n.to.put(num, cost); + return; + } + + if (to.get(nodeNum) > cost) { + to.replace(nodeNum, cost); + n.to.replace(num, cost); + } + } + + public Node(int num) { + this.num = num; + } + + @Override + public int compareTo(Node o) { + + return Integer.compare(totalCost[this.num], totalCost[o.num]); + } + } + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + nodeCnt = Integer.parseInt(st.nextToken()); + edgeCnt = Integer.parseInt(st.nextToken()); + freeCnt = Integer.parseInt(st.nextToken()); + + nodes = new Node[nodeCnt+1]; + visited = new boolean[nodeCnt+1]; + totalCost = new int [nodeCnt+1]; + + for (int i = 1; i <= nodeCnt; i++) { + nodes[i] = new Node(i); + } + + for (int i = 0; i < edgeCnt; i++) { + st = new StringTokenizer(br.readLine()); + int num1 = Integer.parseInt(st.nextToken()); + int num2 = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + + nodes[num1].addEdge(num2, cost); + } + + + } + + public static void process() throws IOException { + + + int start = 0; + int end = 1000000; + + int mid = (start+end)/2; + + int lowestSuccess = Integer.MAX_VALUE; + + while(start < end) { + canReach = false; + djikstra(mid); + System.out.println(mid); + if (canReach) { + end = mid; + + lowestSuccess = Math.min(mid,lowestSuccess); + } + else start = mid+1; + + mid = (start+end)/2; + + + } + + if (lowestSuccess == Integer.MAX_VALUE) { + ans = -1; + } else ans = lowestSuccess; + + } + + + + + + + private static void djikstra(int limit) { + Arrays.fill(totalCost, Integer.MAX_VALUE/2); + Arrays.fill(visited, false); + totalCost[1] = 0; + nodePq.add(nodes[1]); + + + while(!nodePq.isEmpty()) { + Node node = nodePq.poll(); + if (visited[node.num]) continue; + + visited[node.num] = true; + + for (int n: node.to.keySet()) { + int cost = node.to.get(n); + + int temp = totalCost[node.num]; + if (cost > limit) temp++; + + if (temp > freeCnt) continue; + + if (totalCost[n] > temp) { + totalCost[n] = temp; + nodePq.add(nodes[n]); + } + } + + + } + + if (totalCost[nodeCnt] != Integer.MAX_VALUE/2) canReach = true; + + } + + public static void print() { + System.out.println(ans); + } +} + +``` From 908cded786830525206c5f761630336f928e07b8 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 3 Sep 2025 23:22:05 +0900 Subject: [PATCH 093/143] =?UTF-8?q?[20250903]=20BOJ=20/=20D4=20/=20?= =?UTF-8?q?=EA=B7=B8=EB=9E=98=ED=94=84=EC=99=80=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=EC=84=B1=20=EC=BF=BC=EB=A6=AC=20/=20=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\204\261 \354\277\274\353\246\254.md" | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 "khj20006/202509/03 BOJ D4 \352\267\270\353\236\230\355\224\204\354\231\200 \354\227\260\352\262\260\354\204\261 \354\277\274\353\246\254.md" diff --git "a/khj20006/202509/03 BOJ D4 \352\267\270\353\236\230\355\224\204\354\231\200 \354\227\260\352\262\260\354\204\261 \354\277\274\353\246\254.md" "b/khj20006/202509/03 BOJ D4 \352\267\270\353\236\230\355\224\204\354\231\200 \354\227\260\352\262\260\354\204\261 \354\277\274\353\246\254.md" new file mode 100644 index 00000000..692fa0d4 --- /dev/null +++ "b/khj20006/202509/03 BOJ D4 \352\267\270\353\236\230\355\224\204\354\231\200 \354\227\260\352\262\260\354\204\261 \354\277\274\353\246\254.md" @@ -0,0 +1,127 @@ +```cpp +#pragma GCC optimize("O3, unroll-loops") +#include +using namespace std; +using ll = long long; + +int N, M, Q, bucketSize; +vector> edges; +vector> queries; +int res[100000]{}; + +// disjoint set +int root[100001]{}, cnt[100001]{}; +ll ans = 0; +vector> works; +ll g(ll x) { return x*(x-1)/2; } +void u(int a, int b) { + int x = a, y = b; + while(x != root[x]) x = root[x]; + while(y != root[y]) y = root[y]; + if(x == y) { + works.emplace_back(-1,-1,-1); + return; + } + if(cnt[x] > cnt[y]) swap(x,y); + works.emplace_back(x,y,cnt[x]); + ans -= g(cnt[x]) + g(cnt[y]); + cnt[y] += cnt[x]; + ans += g(cnt[y]); + root[x] = y; +} +void rollback() { + auto [x,y,r] = works.back(); works.pop_back(); + if(x == -1) return; + ans -= g(cnt[y]); + cnt[y] -= r; + ans += g(cnt[x]) + g(cnt[y]); + root[x] = x; +} + +// odc +int lifetime[100000]{}; +vector infos[262144]; +int need[100000]{}; +void update(int s, int e, int l, int r, int n, int i) { + if(l>r || l>e || r>1; + update(s,m,l,r,n*2,i); + update(m+1,e,l,r,n*2+1,i); +} +void clear(int s, int e, int n) { + for(int i:infos[n]) { + auto [a,b] = edges[i]; + u(a,b); + } + if(s == e) { + res[need[s]] = ans; + } + else { + int m = (s+e)>>1; + clear(s,m,n*2); + clear(m+1,e,n*2+1); + } + for(int i=0;isync_with_stdio(0); + cout.tie(0); + + cin>>N>>M>>Q; + bucketSize = sqrt(M); + iota(root, root+N+1, 0); + fill(cnt, cnt+N+1, 1); + + edges.resize(M); + for(auto &[a,b]:edges) cin>>a>>b; + + queries.resize(Q); + int tmp = 0; + for(auto &[a,b,c]:queries) cin>>a>>b, a--, b--, c=tmp++; + + sort(queries.begin(), queries.end(), [](auto a, auto b) -> bool{ + auto [al, ar, ax] = a; + auto [bl, br, bx] = b; + int anum = al/bucketSize, bnum = bl/bucketSize; + if(anum == bnum) { + if(anum & 1) return br < ar; + return ar < br; + } + return anum < bnum; + }); + + fill(lifetime, lifetime + M, -1); + int pl = 0, pr = 0, px = 0; + for(int i=0;i=l && lifetime[pr] == -1) lifetime[pr] = i; + } + while(r Date: Wed, 3 Sep 2025 23:41:11 +0900 Subject: [PATCH 094/143] =?UTF-8?q?[20250903]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=B5=9C=EC=86=8C=EB=B9=84=EC=9A=A9=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \352\265\254\355\225\230\352\270\260.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "LiiNi-coder/202509/03 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" diff --git "a/LiiNi-coder/202509/03 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" "b/LiiNi-coder/202509/03 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" new file mode 100644 index 00000000..f80e34b4 --- /dev/null +++ "b/LiiNi-coder/202509/03 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" @@ -0,0 +1,74 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static int n; + private static int m; + private static List[] graph; + private static int[] dist; + + private static class Node implements Comparable { + int v; + int w; + public Node(int v, int w) { + this.v = v; + this.w = w; + } + @Override + public int compareTo(Node other) { + return this.w - other.w; + } + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + n = Integer.parseInt(br.readLine()); + m = Integer.parseInt(br.readLine()); + graph = new ArrayList[n + 1]; + for (int i = 1; i <= n; i++) { + graph[i] = new ArrayList<>(); + } + for (int i = 0; i < m; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + graph[a].add(new Node(b, c)); + } + StringTokenizer st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + dist = new int[n + 1]; + Arrays.fill(dist, Integer.MAX_VALUE); + + dijkstra(start); + + System.out.println(dist[end]); + } + + private static void dijkstra(int start) { + PriorityQueue pq = new PriorityQueue<>(); + dist[start] = 0; + pq.add(new Node(start, 0)); + while (!pq.isEmpty()) { + Node now = pq.poll(); + if (dist[now.v] < now.w) continue; + for (Node next : graph[now.v]) { + if (dist[next.v] > dist[now.v] + next.w) { + dist[next.v] = dist[now.v] + next.w; + pq.add(new Node(next.v, dist[next.v])); + } + } + } + } +} +``` From 01ed0adc92a570cfdb09a44aea48c57bef2f4353 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 4 Sep 2025 08:25:40 +0900 Subject: [PATCH 095/143] =?UTF-8?q?[20250904]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A0=EC=9D=B4=EC=96=B4=20=EB=B2=A8=ED=8A=B8=20?= =?UTF-8?q?=EC=9C=84=EC=9D=98=20=EB=A1=9C=EB=B4=87=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \353\241\234\353\264\207.md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "JHLEE325/202509/04 BOJ G5 \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" diff --git "a/JHLEE325/202509/04 BOJ G5 \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/JHLEE325/202509/04 BOJ G5 \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..a063ac02 --- /dev/null +++ "b/JHLEE325/202509/04 BOJ G5 \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,75 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int n, k; + static int[] str; + static boolean[] robot; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + + str = new int[2 * n]; + robot = new boolean[n]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < 2 * n; i++) { + str[i] = Integer.parseInt(st.nextToken()); + } + + int stage = 0; + while (true) { + stage++; + + int laststr = str[2 * n - 1]; + for (int i = 2 * n - 1; i > 0; i--) { + str[i] = str[i - 1]; + } + str[0] = laststr; + + for (int i = n - 1; i > 0; i--) { + robot[i] = robot[i - 1]; + } + robot[0] = false; + + if (robot[n - 1]) { + robot[n - 1] = false; + } + + for (int i = n - 2; i >= 0; i--) { + if (robot[i] && !robot[i + 1] && str[i + 1] >= 1) { + robot[i] = false; + robot[i + 1] = true; + str[i + 1]--; + } + } + + if (robot[n - 1]) { + robot[n - 1] = false; + } + + if (str[0] > 0) { + robot[0] = true; + str[0]--; + } + + int zerostr = 0; + for (int d : str) { + if (d == 0) { + zerostr++; + } + } + if (zerostr >= k) { + break; + } + } + + System.out.println(stage); + } +} +``` From 507fae2298f445a56a1f1aa7c694e531185e4254 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Thu, 4 Sep 2025 15:30:35 +0900 Subject: [PATCH 096/143] =?UTF-8?q?[20250904]=20PGM=20/=20LV3=20/=20[1?= =?UTF-8?q?=EC=B0=A8]=20=EC=85=94=ED=8B=80=EB=B2=84=EC=8A=A4=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\355\213\200\353\262\204\354\212\244.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "suyeun84/202509/04 PGM LV3 [1\354\260\250] \354\205\224\355\213\200\353\262\204\354\212\244.md" diff --git "a/suyeun84/202509/04 PGM LV3 [1\354\260\250] \354\205\224\355\213\200\353\262\204\354\212\244.md" "b/suyeun84/202509/04 PGM LV3 [1\354\260\250] \354\205\224\355\213\200\353\262\204\354\212\244.md" new file mode 100644 index 00000000..bd833962 --- /dev/null +++ "b/suyeun84/202509/04 PGM LV3 [1\354\260\250] \354\205\224\355\213\200\353\262\204\354\212\244.md" @@ -0,0 +1,42 @@ +```java +import java.util.*; +class Solution { + public String solution(int n, int t, int m, String[] timetable) { + int answer = 0; + PriorityQueue pq = new PriorityQueue<>(); + // 크루 도착 시간 + for (String time : timetable) pq.add(convertToTime(time)); + + int departTime = 9*60; + List> bus = new ArrayList<>(); + // 각 버스에 타는 크루 저장 + for (int i = 0; i < n; i++) bus.add(new ArrayList<>()); + + for (int i = 0; i < n; i++) { + while (!pq.isEmpty()) { + int crew = pq.poll(); + if (bus.get(i).size() < m && crew <= departTime) { + bus.get(i).add(crew); + answer = crew - 1; + } else { + pq.add(crew); + break; + } + } + departTime += t; + } + + if (bus.get(n-1).size() < m) answer = departTime - t; + return convertToString(answer); + } + + static int convertToTime(String s) { + String[] a = s.split(":"); + return Integer.parseInt(a[0]) * 60 + Integer.parseInt(a[1]); + } + + static String convertToString(int time) { + return String.format("%02d:%02d", time / 60, time % 60); + } +} +``` From 6d4e369d7051ea7e314067ff42ad584dd639fe0a Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Thu, 4 Sep 2025 20:47:25 +0900 Subject: [PATCH 097/143] =?UTF-8?q?[20250904]=20BOJ=20/=20P5=20/=20Two=20M?= =?UTF-8?q?achines=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ukj0ng/202509/4 BOJ P5 Two Machines.md | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Ukj0ng/202509/4 BOJ P5 Two Machines.md diff --git a/Ukj0ng/202509/4 BOJ P5 Two Machines.md b/Ukj0ng/202509/4 BOJ P5 Two Machines.md new file mode 100644 index 00000000..a595384c --- /dev/null +++ b/Ukj0ng/202509/4 BOJ P5 Two Machines.md @@ -0,0 +1,68 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final int INF = 70000; + private static int[][] task; + private static int[][] dp; + private static int N, maxTime; + + public static void main(String[] args) throws IOException { + init(); + DP(); + + int answer = INF; + for (int j = 0; j <= maxTime; j++) { + if (dp[N][j] != INF) { + answer = Math.min(answer, Math.max(j, dp[N][j])); + } + } + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + int a = 0; + int b = 0; + + task = new int[2][N]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + task[0][i] = Integer.parseInt(st.nextToken()); + task[1][i] = Integer.parseInt(st.nextToken()); + + a += task[0][i]; + b += task[1][i]; + } + + maxTime = Math.max(a, b); + + dp = new int[N + 1][maxTime + 1]; + for (int i = 0; i <= N; i++) { + Arrays.fill(dp[i], INF); + } + dp[0][0] = 0; + } + + private static void DP() { + for (int i = 0; i < N; i++) { + for (int j = 0; j <= maxTime; j++) { + if (dp[i][j] == INF) continue; + + if (j + task[0][i] <= maxTime) dp[i + 1][j + task[0][i]] = Math.min(dp[i + 1][j + task[0][i]], dp[i][j]); + + dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j] + task[1][i]); + } + } + } +} + +``` From 2235cc1719d2835e5037f4d06b24968f4e5a24c5 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Thu, 4 Sep 2025 22:01:46 +0900 Subject: [PATCH 098/143] =?UTF-8?q?[20250904]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=ED=83=9D=EB=B0=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202508/4 BOJ \355\203\235\353\260\260.md" | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 "0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" diff --git "a/0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" "b/0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" new file mode 100644 index 00000000..a2675f92 --- /dev/null +++ "b/0224LJH/202508/4 BOJ \355\203\235\353\260\260.md" @@ -0,0 +1,125 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + static int villageCnt, totalSpace, curSpace,ans, deliveryCnt; + static PriorityQueue pq = new PriorityQueue<>(); + static int[] spaces; + static Delivery[] deliveries; + + + static class Delivery implements Comparable{ + int from; + int to; + int boxCnt; + int overlap = 0; + + public Delivery(int from, int to, int boxCnt) { + this.from = from; + this.to = to; + this.boxCnt = boxCnt; + } + + @Override + public int compareTo(Delivery d) { + + return Integer.compare(this.to,d.to); + } + } + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + villageCnt = Integer.parseInt(st.nextToken()); + totalSpace =Integer.parseInt(st.nextToken()); + curSpace = 0; + ans = 0; + + spaces = new int[villageCnt+1]; + deliveryCnt = Integer.parseInt(br.readLine()); + deliveries = new Delivery[deliveryCnt]; + + for (int i = 0; i < deliveryCnt; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int boxCnt = Integer.parseInt(st.nextToken()); + + Delivery d = new Delivery(from,to,boxCnt); + deliveries[i] = d; + + } + + + + } + + public static void process() throws IOException { + getOverlap(); + for (int i = 0; i < deliveryCnt; i++) pq.add(deliveries[i]); + + while(!pq.isEmpty()) { + Delivery d = pq.poll(); + + put(d); + } + + + } + + public static void put(Delivery d) { + + int limit = d.boxCnt; + + for (int i = d.from; i < d.to; i++) { + limit = Math.min(limit, totalSpace - spaces[i]); + } + + for (int i = d.from; i Date: Thu, 4 Sep 2025 22:03:26 +0900 Subject: [PATCH 099/143] =?UTF-8?q?[20250904]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=ED=83=9D=EB=B0=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202509/4 BOJ \355\203\235\353\260\260.md" | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 "0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" diff --git "a/0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" "b/0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" new file mode 100644 index 00000000..a2675f92 --- /dev/null +++ "b/0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" @@ -0,0 +1,125 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + static int villageCnt, totalSpace, curSpace,ans, deliveryCnt; + static PriorityQueue pq = new PriorityQueue<>(); + static int[] spaces; + static Delivery[] deliveries; + + + static class Delivery implements Comparable{ + int from; + int to; + int boxCnt; + int overlap = 0; + + public Delivery(int from, int to, int boxCnt) { + this.from = from; + this.to = to; + this.boxCnt = boxCnt; + } + + @Override + public int compareTo(Delivery d) { + + return Integer.compare(this.to,d.to); + } + } + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + villageCnt = Integer.parseInt(st.nextToken()); + totalSpace =Integer.parseInt(st.nextToken()); + curSpace = 0; + ans = 0; + + spaces = new int[villageCnt+1]; + deliveryCnt = Integer.parseInt(br.readLine()); + deliveries = new Delivery[deliveryCnt]; + + for (int i = 0; i < deliveryCnt; i++) { + st = new StringTokenizer(br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int boxCnt = Integer.parseInt(st.nextToken()); + + Delivery d = new Delivery(from,to,boxCnt); + deliveries[i] = d; + + } + + + + } + + public static void process() throws IOException { + getOverlap(); + for (int i = 0; i < deliveryCnt; i++) pq.add(deliveries[i]); + + while(!pq.isEmpty()) { + Delivery d = pq.poll(); + + put(d); + } + + + } + + public static void put(Delivery d) { + + int limit = d.boxCnt; + + for (int i = d.from; i < d.to; i++) { + limit = Math.min(limit, totalSpace - spaces[i]); + } + + for (int i = d.from; i Date: Thu, 4 Sep 2025 22:04:24 +0900 Subject: [PATCH 100/143] =?UTF-8?q?[20250904]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=ED=83=9D=EB=B0=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202509/04 BOJ \355\203\235\353\260\260.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" => "0224LJH/202509/04 BOJ \355\203\235\353\260\260.md" (100%) diff --git "a/0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" "b/0224LJH/202509/04 BOJ \355\203\235\353\260\260.md" similarity index 100% rename from "0224LJH/202509/4 BOJ \355\203\235\353\260\260.md" rename to "0224LJH/202509/04 BOJ \355\203\235\353\260\260.md" From 55dbef282ede6d30cd5789ba54fbe41d73472136 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 4 Sep 2025 22:11:24 +0900 Subject: [PATCH 101/143] =?UTF-8?q?[20250904]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=EC=A7=95=EA=B2=80=EB=8B=A4=EB=A6=AC=20=EB=92=A4=EB=A1=9C=20?= =?UTF-8?q?=EA=B1=B4=EB=84=88=EA=B8=B0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\261\264\353\204\210\352\270\260.md" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" diff --git "a/khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" "b/khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" new file mode 100644 index 00000000..2287703d --- /dev/null +++ "b/khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" @@ -0,0 +1,90 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final long MOD = (long)1e9 + 7; + + static int N, K; + static long[][] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + K = io.nextInt(); + if(N <= 2) { + io.write("1\n"); + return; + } + + dp = new long[N+1][K+1]; + for(int i=3;i<=N;i++) for(int x=1;x<=K && i-x>0;x++) { + if(i-x <= 2) dp[i][x] = (dp[i][x] + 1) % MOD; + else for(int y=1;y<=K && i-x-y>0;y++) { + if(i-x-y <= 2) dp[i][x] = (dp[i][x] + (i-x+1-Math.max(i-x-y+1,i-K))) % MOD; + else dp[i][x] = (dp[i][x] + dp[i-x][y] * (i-x+1-Math.max(i-x-y+1,i-K))) % MOD; + } + } + + long ans = 0; + for(int x=1;x<=K && N-x>0;x++) ans = (ans + dp[N][x]) % MOD; + io.write(ans + "\n"); + + io.close(); + + } + +} +``` From 90c1b8d293f1de8f2e7647807b2ca697609fe13d Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Thu, 4 Sep 2025 23:10:51 +0900 Subject: [PATCH 102/143] =?UTF-8?q?[20250904]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=8F=99=EC=A0=842=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../04 BOJ \353\217\231\354\240\2042.md" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "LiiNi-coder/202509/04 BOJ \353\217\231\354\240\2042.md" diff --git "a/LiiNi-coder/202509/04 BOJ \353\217\231\354\240\2042.md" "b/LiiNi-coder/202509/04 BOJ \353\217\231\354\240\2042.md" new file mode 100644 index 00000000..dabbed96 --- /dev/null +++ "b/LiiNi-coder/202509/04 BOJ \353\217\231\354\240\2042.md" @@ -0,0 +1,41 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static StringTokenizer st; + private static int n, k; + private static int[] coins; + private static int[] dp; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + coins = new int[n]; + for (int i = 0; i < n; i++) { + coins[i] = Integer.parseInt(br.readLine()); + } + + dp = new int[k + 1]; + Arrays.fill(dp, Integer.MAX_VALUE); + dp[0] = 0; + for (int coin : coins) { + if (coin > k) + continue; + for (int j = coin; j <= k; j++) { + if (dp[j - coin] == Integer.MAX_VALUE) + continue; + dp[j] = Math.min(dp[j], dp[j-coin] + 1); + } + } + + System.out.println((dp[k] == Integer.MAX_VALUE) ? -1 : dp[k]); + } +} +``` From 074191c4e89b87d39b8138e37bd1beb16dab0e19 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Fri, 5 Sep 2025 08:23:01 +0900 Subject: [PATCH 103/143] =?UTF-8?q?[20250905]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=20=EA=B3=B1=20=EA=B5=AC=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \352\265\254\355\225\230\352\270\260.md" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "JHLEE325/202509/05 BOJ G1 \352\265\254\352\260\204 \352\263\261 \352\265\254\355\225\230\352\270\260.md" diff --git "a/JHLEE325/202509/05 BOJ G1 \352\265\254\352\260\204 \352\263\261 \352\265\254\355\225\230\352\270\260.md" "b/JHLEE325/202509/05 BOJ G1 \352\265\254\352\260\204 \352\263\261 \352\265\254\355\225\230\352\270\260.md" new file mode 100644 index 00000000..d5b41421 --- /dev/null +++ "b/JHLEE325/202509/05 BOJ G1 \352\265\254\352\260\204 \352\263\261 \352\265\254\355\225\230\352\270\260.md" @@ -0,0 +1,77 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + long[] arr = new long[n]; + long[] tree = new long[4 * n]; + + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(br.readLine()); + } + + init(arr, tree, 1, 0, n - 1); + + for (int i = 0; i < m + k; i++) { + st = new StringTokenizer(br.readLine()); + int op = Integer.parseInt(st.nextToken()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + if (op == 2) { + sb.append(query(tree, 1, 0, n - 1, a - 1, b - 1) + "\n"); + } else { + update(arr, tree, 1, 0, n - 1, a - 1, b); + } + } + + System.out.println(sb.toString()); + } + + static void init(long[] arr, long[] tree, int node, int start, int end) { + if (start == end) { + tree[node] = arr[start]; + } else { + init(arr, tree, node * 2, start, (start + end) / 2); + init(arr, tree, node * 2 + 1, (start + end) / 2 + 1, end); + tree[node] = tree[node * 2] * tree[node * 2 + 1] % 1000000007; + } + } + + static void update(long[] arr, long[] tree, int node, int start, int end, int index, long val) { + if (index < start || index > end) { + return; + } + if (start == end) { + arr[index] = val; + tree[node] = val; + return; + } + update(arr, tree, node * 2, start, (start + end) / 2, index, val); + update(arr, tree, node * 2 + 1, (start + end) / 2 + 1, end, index, val); + tree[node] = tree[node * 2] * tree[node * 2 + 1] % 1000000007; + } + + static long query(long[] tree, int node, int start, int end, int left, int right) { + if (left > end || right < start) { + return 1; + } + if (left <= start && end <= right) { + return tree[node]; + } + long lmul = query(tree, node * 2, start, (start + end) / 2, left, right); + long rmul = query(tree, node * 2 + 1, (start + end) / 2 + 1, end, left, right); + return lmul * rmul % 1000000007; + } +} +``` From d69dff50dd4db81ef9d3a2ac77d2ff58fb1bfdd2 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Fri, 5 Sep 2025 09:12:33 +0900 Subject: [PATCH 104/143] =?UTF-8?q?[20250905]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=9D=B4=EB=B6=84=20=EA=B7=B8=EB=9E=98=ED=94=84=20/=20?= =?UTF-8?q?=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\267\270\353\236\230\355\224\204.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "Ukj0ng/202509/5 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" diff --git "a/Ukj0ng/202509/5 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" "b/Ukj0ng/202509/5 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" new file mode 100644 index 00000000..80c7179d --- /dev/null +++ "b/Ukj0ng/202509/5 BOJ G4 \354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.md" @@ -0,0 +1,81 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static List[] graph; + private static int[] visited; + private static int V, E; + + public static void main(String[] args) throws IOException { + int K = Integer.parseInt(br.readLine()); + + while (K-- > 0) { + init(); + + boolean result = true; + + for (int i = 1; i <= V; i++) { + if (visited[i] == 0) { + result = BFS(i); + } + + if (!result) break; + } + + if (result) bw.write("YES" + "\n"); + else bw.write("NO" + "\n"); + } + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + V = Integer.parseInt(st.nextToken()); + E = Integer.parseInt(st.nextToken()); + + visited = new int[V + 1]; + graph = new List[V + 1]; + + for (int i = 0; i <= V; i++) { + graph[i] = new ArrayList<>(); + } + + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + graph[a].add(b); + graph[b].add(a); + } + } + + private static boolean BFS(int start) { + Queue q = new ArrayDeque<>(); + visited[start] = 1; + q.add(start); + + while (!q.isEmpty()) { + int current = q.poll(); + + for (int next : graph[current]) { + if (visited[next] == visited[current]) return false; + + if (visited[next] == 0) { + visited[next] = 3 - visited[current]; + q.add(next); + } + } + } + + return true; + } +} +``` From 11068be051d7f25d89ff693c4170cd1f1fe9d175 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:27:47 +0900 Subject: [PATCH 105/143] =?UTF-8?q?[20250905]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=ED=8A=B8=EB=A6=AC=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../05 BOJ G4 \355\212\270\353\246\254.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "lkhyun/202509/05 BOJ G4 \355\212\270\353\246\254.md" diff --git "a/lkhyun/202509/05 BOJ G4 \355\212\270\353\246\254.md" "b/lkhyun/202509/05 BOJ G4 \355\212\270\353\246\254.md" new file mode 100644 index 00000000..9b3cbaba --- /dev/null +++ "b/lkhyun/202509/05 BOJ G4 \355\212\270\353\246\254.md" @@ -0,0 +1,72 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + static int N,M; + static int T; + public static void main(String[] args) throws Exception { + T = 1; + while(true){ + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + if(N == 0 && M == 0) break; + sb.append("Case ").append(T++).append(": " ); + + int[] parent = new int[N+1]; + for (int i = 1; i <= N; i++) { + parent[i] = i; + } + + Set cycles = new HashSet<>(); + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + union(a, b, parent, cycles); + } + + Set s = new HashSet<>(); + for (int i = 1; i <= N; i++) { + s.add(find(i,parent)); + } + + for(int c : cycles){ + s.remove(find(c,parent)); + } + + if(s.size()==0){ + sb.append("No trees.\n"); + }else if(s.size()==1){ + sb.append("There is one tree.\n"); + }else{ + sb.append("A forest of ").append(s.size()).append(" trees.\n"); + } + } + bw.write(sb.toString()); + bw.close(); + } + public static int find(int cur, int[] parent){ + if(parent[cur] == cur) return cur; + else return parent[cur] = find(parent[cur],parent); + } + public static void union(int a, int b, int[] parent, Set cycles){ + int rootA = find(a,parent); + int rootB = find(b,parent); + + if(rootA < rootB){ + parent[rootA] = rootB; + }else if(rootA > rootB){ + parent[rootB] = rootA; + }else{ + cycles.add(rootA); + } + } +} +``` From 440e8d000f28fc200481e718a1bc33accadb6bae Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 5 Sep 2025 17:03:17 +0900 Subject: [PATCH 106/143] =?UTF-8?q?[20250905]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EC=84=AC=20=EC=97=B0=EA=B2=B0=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\352\262\260\355\225\230\352\270\260.md" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" diff --git "a/suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" "b/suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" new file mode 100644 index 00000000..a3674179 --- /dev/null +++ "b/suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" @@ -0,0 +1,23 @@ +```java +import java.util.*; +class Solution { + public int solution(int n, int[][] costs) { + int answer = 0; + HashSet set = new HashSet<>(); + Arrays.sort(costs, (o1, o2) -> o1[2] - o2[2]); + set.add(costs[0][0]); + while (set.size() < n) { + for (int[] cost : costs) { + if (set.contains(cost[0]) && set.contains(cost[1])) continue; + else if (set.contains(cost[0]) || set.contains(cost[1])) { + set.add(cost[0]); + set.add(cost[1]); + answer += cost[2]; + break; + } + } + } + return answer; + } +} +``` From bba0336d1aed35f820af9fed234f497ad8e37783 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Fri, 5 Sep 2025 21:03:23 +0900 Subject: [PATCH 107/143] =?UTF-8?q?[20250905]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=8F=99=EC=A0=841=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202509/05 BOJ \353\217\231\354\240\2041" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "0224LJH/202509/05 BOJ \353\217\231\354\240\2041" diff --git "a/0224LJH/202509/05 BOJ \353\217\231\354\240\2041" "b/0224LJH/202509/05 BOJ \353\217\231\354\240\2041" new file mode 100644 index 00000000..1a465a27 --- /dev/null +++ "b/0224LJH/202509/05 BOJ \353\217\231\354\240\2041" @@ -0,0 +1,57 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + static int[] dp,coins; + static int coinCnt, goal; + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + coinCnt = Integer.parseInt(st.nextToken()); + goal = Integer.parseInt(st.nextToken()); + + coins = new int[coinCnt]; + dp = new int[goal+1]; + dp[0] = 1; + + for (int i = 0; i < coinCnt; i++) { + coins[i] = Integer.parseInt(br.readLine()); + } + + + } + + public static void process() throws IOException { + + for (int i = 0; i < coinCnt; i++) { + int cost = coins[i]; + + for (int j = cost; j <= goal; j++) { + dp[j] += dp[j-cost]; + } + } + + } + + + + + + + + public static void print() { + System.out.println(dp[goal]); + } +} + +``` From e37244b9dbeb57a633ffd86f8bff1083ff87adeb Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 5 Sep 2025 23:51:53 +0900 Subject: [PATCH 108/143] =?UTF-8?q?[20250905]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=86=9C=20=EC=82=AC=EC=9D=B4=20=EC=88=98=EC=97=B4=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\264 \354\210\230\354\227\264.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "LiiNi-coder/202509/05 BOJ \354\206\234 \354\202\254\354\235\264 \354\210\230\354\227\264.md" diff --git "a/LiiNi-coder/202509/05 BOJ \354\206\234 \354\202\254\354\235\264 \354\210\230\354\227\264.md" "b/LiiNi-coder/202509/05 BOJ \354\206\234 \354\202\254\354\235\264 \354\210\230\354\227\264.md" new file mode 100644 index 00000000..31d2d21d --- /dev/null +++ "b/LiiNi-coder/202509/05 BOJ \354\206\234 \354\202\254\354\235\264 \354\210\230\354\227\264.md" @@ -0,0 +1,72 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static int N; + private static int[] X; + private static int[] answer; + private static boolean[] used; + private static boolean found; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + X = new int[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + X[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(X); + answer = new int[2 * N]; + Arrays.fill(answer, -1); + used = new boolean[N]; + + backtrack(0); + + if (!found) { + System.out.println(-1); + } + } + + private static void backtrack(int idx) { + if (found) + return; + + + if (idx == 2 * N) { + StringBuilder sb = new StringBuilder(); + for (int v : answer) sb.append(v).append(' '); + System.out.println(sb.toString()); + found = true; + return; + } + if (answer[idx] != -1) { + backtrack(idx + 1); + return; + } + + for (int i = 0; i < N; i++) { + if (used[i]) + continue; + int val = X[i]; + int secIdx = idx + val + 1; + if (secIdx >= 2 * N || answer[secIdx] != -1) continue; + + answer[idx] = val; + answer[secIdx] = val; + used[i] = true; + + backtrack(idx + 1); + + answer[idx] = -1; + answer[secIdx] = -1; + used[i] = false; + } + } +} +``` From 5bc1329a5073f774596923a8eccce45df74646e9 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sat, 6 Sep 2025 15:34:02 +0900 Subject: [PATCH 109/143] =?UTF-8?q?[20250906]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=83=81=EB=B2=94=20=EB=B9=8C=EB=94=A9=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\353\262\224 \353\271\214\353\224\251.md" | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 "JHLEE325/202509/06 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" diff --git "a/JHLEE325/202509/06 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" "b/JHLEE325/202509/06 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" new file mode 100644 index 00000000..28d14f8b --- /dev/null +++ "b/JHLEE325/202509/06 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" @@ -0,0 +1,96 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static class Point { + int l, r, c, time; + + public Point(int l, int r, int c, int time) { + this.l = l; + this.r = r; + this.c = c; + this.time = time; + } + } + + static int l, r, c; + static char[][][] building; + static boolean[][][] visited; + static int[] dl = {0, 0, 0, 0, -1, 1}; + static int[] dr = {0, 0, -1, 1, 0, 0}; + static int[] dc = {-1, 1, 0, 0, 0, 0}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder sb = new StringBuilder(); + + while (true) { + StringTokenizer st = new StringTokenizer(br.readLine()); + l = Integer.parseInt(st.nextToken()); + r = Integer.parseInt(st.nextToken()); + c = Integer.parseInt(st.nextToken()); + + if (l == 0 && r == 0 && c == 0) { + break; + } + + building = new char[l][r][c]; + visited = new boolean[l][r][c]; + Point start = null; + + for (int l = 0; l < Main.l; l++) { + for (int r = 0; r < Main.r; r++) { + String line = br.readLine(); + for (int c = 0; c < Main.c; c++) { + building[l][r][c] = line.charAt(c); + if (building[l][r][c] == 'S') { + start = new Point(l, r, c, 0); + } + } + } + br.readLine(); + } + + int result = bfs(start); + + if (result == -1) { + sb.append("Trapped!\n"); + } else { + sb.append("Escaped in ").append(result).append(" minute(s).\n"); + } + } + System.out.print(sb); + } + + static int bfs(Point start) { + Queue queue = new LinkedList<>(); + queue.offer(start); + visited[start.l][start.r][start.c] = true; + + while (!queue.isEmpty()) { + Point cur = queue.poll(); + + if (building[cur.l][cur.r][cur.c] == 'E') { + return cur.time; + } + + for (int i = 0; i < 6; i++) { + int nl = cur.l + dl[i]; + int nr = cur.r + dr[i]; + int nc = cur.c + dc[i]; + + if (nl >= 0 && nl < l && nr >= 0 && nr < r && nc >= 0 && nc < c) { + if (!visited[nl][nr][nc] && building[nl][nr][nc] != '#') { + visited[nl][nr][nc] = true; + queue.offer(new Point(nl, nr, nc, cur.time + 1)); + } + } + } + } + + return -1; + } +} +``` From 00ed6a69e3edd5b63f9064f470cf1cffa7ebdb14 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sat, 6 Sep 2025 17:09:39 +0900 Subject: [PATCH 110/143] =?UTF-8?q?[20250906]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EB=B6=88=EB=9F=89=20=EC=82=AC=EC=9A=A9=EC=9E=90=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \354\202\254\354\232\251\354\236\220.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "suyeun84/202509/06 PGM LV3 \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.md" diff --git "a/suyeun84/202509/06 PGM LV3 \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.md" "b/suyeun84/202509/06 PGM LV3 \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.md" new file mode 100644 index 00000000..29e50d95 --- /dev/null +++ "b/suyeun84/202509/06 PGM LV3 \353\266\210\353\237\211 \354\202\254\354\232\251\354\236\220.md" @@ -0,0 +1,37 @@ +```java +import java.util.*; +class Solution { + public int solution(String[] user_id, String[] banned_id) { + HashSet> result = new HashSet<>(); + + dfs(new HashSet<>(), user_id, banned_id, result); + return result.size(); + } + + private void dfs(HashSet hashset, String[] user_id, String[] banned_id, HashSet> result) { + if (hashset.size() == banned_id.length) { + result.add(new HashSet<>(hashset)); + return; + }; + String target = banned_id[hashset.size()]; + + for (String user : user_id) { + if (hashset.contains(user)) continue; + if (check(target, user)) { + hashset.add(user); + dfs(hashset, user_id, banned_id, result); + hashset.remove(user); + } + } + } + private boolean check(String target, String user) { + if (target.length() != user.length()) return false; + for (int j = 0; j < target.length(); j++) { + if (target.charAt(j) == ('*')) continue; + if (target.charAt(j) == user.charAt(j)) continue; + return false; + } + return true; + } +} +``` From 250f95a850135f777d60d43e2b47efcdb425ae36 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 6 Sep 2025 17:14:52 +0900 Subject: [PATCH 111/143] =?UTF-8?q?[20250906]=20BOJ=20/=20G2=20/=20?= =?UTF-8?q?=EB=A9=80=EC=A7=80=EB=A7=8C=20=EA=B0=80=EA=B9=8C=EC=9A=B4=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\232\264 \354\202\254\354\235\264.md" | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 "khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" diff --git "a/khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" "b/khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" new file mode 100644 index 00000000..4d4aef08 --- /dev/null +++ "b/khj20006/202509/06 BOJ G2 \353\251\200\354\247\200\353\247\214 \352\260\200\352\271\214\354\232\264 \354\202\254\354\235\264.md" @@ -0,0 +1,111 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static List[] graph; + static List list; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + list = new ArrayList<>(); + graph = new List[N+1]; + for(int i=1;i<=N;i++) graph[i] = new ArrayList<>(); + for(int i=1;i q = new ArrayDeque<>(); + boolean[] vis = new boolean[N+1]; + q.offer(new int[]{1,0}); + vis[1] = true; + while(!q.isEmpty()) { + int[] cur = q.poll(); + int n = cur[0], v = cur[1]; + list.add(v); + for(int[] e:graph[n]) if(!vis[e[0]]) { + vis[e[0]] = true; + q.offer(new int[]{e[0],v^e[1]}); + } + } + Collections.sort(list); + + long ans = 0, cnt = 1; + int prev = list.get(0); + for(int i=1;i Date: Sat, 6 Sep 2025 17:24:05 +0900 Subject: [PATCH 112/143] =?UTF-8?q?[20250906]=20BOJ=20/=20G3=20/=20A=20Bug?= =?UTF-8?q?'s=20Life=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ukj0ng/202509/6 BOJ G3 A Bug's Life.md | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Ukj0ng/202509/6 BOJ G3 A Bug's Life.md diff --git a/Ukj0ng/202509/6 BOJ G3 A Bug's Life.md b/Ukj0ng/202509/6 BOJ G3 A Bug's Life.md new file mode 100644 index 00000000..90715311 --- /dev/null +++ b/Ukj0ng/202509/6 BOJ G3 A Bug's Life.md @@ -0,0 +1,78 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static List[] graph; + private static int[] visited; + private static int N, M; + + public static void main(String[] args) throws IOException { + int T = Integer.parseInt(br.readLine()); + + for (int i = 1; i <= T; i++) { + init(); + boolean result = true; + + for (int ii = 1; ii <= N; ii++) { + if (visited[ii] == 0) { + result = BFS(ii); + } + + if (!result) break; + } + + bw.write(String.format("Scenario #%d:\n", i)); + if (result) bw.write("No suspicious bugs found!\n\n"); + else bw.write("Suspicious bugs found!\n\n"); + } + + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + graph = new List[N+1]; + visited = new int[N+1]; + + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + graph[a].add(b); + graph[b].add(a); + } + } + + private static boolean BFS(int start) { + Queue q = new ArrayDeque<>(); + visited[start] = 1; + q.add(start); + + while (!q.isEmpty()) { + int current = q.poll(); + + for (int next : graph[current]) { + if (visited[next] == 0) { + visited[next] = 3 - visited[current]; + q.add(next); + } else if (visited[next] == visited[current]) return false; + } + } + + return true; + } +} +``` From a767c28900f4793a6de777edd11abee05bd1ce66 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 6 Sep 2025 17:23:35 +0900 Subject: [PATCH 113/143] =?UTF-8?q?[20250906]=20BOJ=20/=20G4=20/=202?= =?UTF-8?q?=EB=A1=9C=20=EB=AA=87=EB=B2=88=20=EB=82=98=EB=88=84=EC=96=B4?= =?UTF-8?q?=EC=A7=88=EA=B9=8C=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\354\226\264\354\247\210\352\271\214.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "0224LJH/202509/06 BOJ 2\353\241\234 \353\252\207\353\262\210 \353\202\230\353\210\204\354\226\264\354\247\210\352\271\214.md" diff --git "a/0224LJH/202509/06 BOJ 2\353\241\234 \353\252\207\353\262\210 \353\202\230\353\210\204\354\226\264\354\247\210\352\271\214.md" "b/0224LJH/202509/06 BOJ 2\353\241\234 \353\252\207\353\262\210 \353\202\230\353\210\204\354\226\264\354\247\210\352\271\214.md" new file mode 100644 index 00000000..cff772c2 --- /dev/null +++ "b/0224LJH/202509/06 BOJ 2\353\241\234 \353\252\207\353\262\210 \353\202\230\353\210\204\354\226\264\354\247\210\352\271\214.md" @@ -0,0 +1,59 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + static long from,to,sum; + static long[] cnts = new long[61]; + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + from = Long.parseLong(st.nextToken()); + to = Long.parseLong(st.nextToken()); + + + } + + public static void process() throws IOException { + for (int i = 0; i < 61; i++) { + long num = 1L << i; + + long cnt = to/num - from/num; + if (from%num == 0) cnt++; + + cnts[i] = cnt; + } + + sum = 0; + long pre = 0; + for (int i = 60; i >= 0; i--) { + long num = 1L << i; + + sum += (cnts[i]-pre) * num; + pre = cnts[i]; + } + + } + + + + + + + + public static void print() { + System.out.println(sum); + } +} + +``` From 3fe2f093ff9e6ad1468539bf27db75e367c9832a Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sat, 6 Sep 2025 23:47:55 +0900 Subject: [PATCH 114/143] =?UTF-8?q?[20250906]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=B5=9C=EC=86=8C=20=EC=8A=A4=ED=8C=A8=EB=8B=9D=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\213\235 \355\212\270\353\246\254.md" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "LiiNi-coder/202509/06 BOJ \354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.md" diff --git "a/LiiNi-coder/202509/06 BOJ \354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.md" "b/LiiNi-coder/202509/06 BOJ \354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.md" new file mode 100644 index 00000000..fd028c05 --- /dev/null +++ "b/LiiNi-coder/202509/06 BOJ \354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.md" @@ -0,0 +1,79 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + private static int V, E; + private static ArrayList[] adj; + private static boolean[] visited; + private static class Edge implements Comparable { + int to, weight; + public Edge(int to, int weight) { + this.to = to; + this.weight = weight; + } + @Override + public int compareTo(Edge other) { + return this.weight - other.weight; + } + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + V = Integer.parseInt(st.nextToken()); + E = Integer.parseInt(st.nextToken()); + adj = new ArrayList[V + 1]; + for (int i = 1; i <= V; i++) { + adj[i] = new ArrayList<>(); + } + + for (int i = 0; i < E; i++) { + st = new StringTokenizer(br.readLine()); + int u = Integer.parseInt(st.nextToken()); + int v = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + + adj[u].add(new Edge(v, w)); + adj[v].add(new Edge(u, w)); + } + + System.out.println(prim()); + } + + private static long prim() { + boolean[] visited = new boolean[V + 1]; + PriorityQueue pq = new PriorityQueue<>(); + long totalWeight = 0; + int visitedCount = 0; + + visited[1] = true; + visitedCount++; + for (Edge e : adj[1]) { + pq.add(e); + } + + while (!pq.isEmpty()) { + Edge edge = pq.poll(); + if (visited[edge.to]) continue; + visited[edge.to] = true; + totalWeight += edge.weight; + visitedCount++; + for (Edge e : adj[edge.to]) { + if (!visited[e.to]) { + pq.add(e); + } + } + if (visitedCount == V) break; + } + + return totalWeight; + } +} + +``` From b226acf321b04d71db783e4b74c06b24ca182dfd Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sun, 7 Sep 2025 18:47:05 +0900 Subject: [PATCH 115/143] =?UTF-8?q?[20250907]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=B1=80=EA=B3=BC=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\246\254 \352\262\214\354\236\204.md" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "Ukj0ng/202509/7 BOJ G5 \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" diff --git "a/Ukj0ng/202509/7 BOJ G5 \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" "b/Ukj0ng/202509/7 BOJ G5 \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" new file mode 100644 index 00000000..6bcd07fd --- /dev/null +++ "b/Ukj0ng/202509/7 BOJ G5 \353\261\200\352\263\274 \354\202\254\353\213\244\353\246\254 \352\262\214\354\236\204.md" @@ -0,0 +1,70 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[] board; + private static boolean[] visited; + private static int N, M; + + public static void main(String[] args) throws IOException { + init(); + int answer = BFS(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + board = new int[101]; + visited = new boolean[101]; + + for (int i = 0; i < N+M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + + board[a] = b; + } + } + + private static int BFS() { + Queue q = new ArrayDeque<>(); + int result = 0; + visited[1] = true; + q.add(new int[] {1, 0}); + + while (!q.isEmpty()) { + int[] current = q.poll(); + + if (current[0] == 100) { + result = current[1]; + break; + } + + for (int i = 1; i <= 6; i++) { + int next = current[0] + i; + if (next > 100) continue; + + if (board[next] != 0) { + next = board[next]; + } + + if (visited[next]) continue; + visited[next] = true; + q.add(new int[]{next, current[1] + 1}); + } + } + + return result; + } +} +``` From 4b6ce5ffb64cdbf377775eff0eb8096aa51be243 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:52:54 +0900 Subject: [PATCH 116/143] =?UTF-8?q?[20250907]=20PGM=20/=20LV3=20/=20?= =?UTF-8?q?=EC=95=BC=EA=B7=BC=20=EC=A7=80=EC=88=98=20/=20=EC=9D=B4?= =?UTF-8?q?=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\267\274 \354\247\200\354\210\230.md" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "lkhyun/202509/07 PGM LV3 \354\225\274\352\267\274 \354\247\200\354\210\230.md" diff --git "a/lkhyun/202509/07 PGM LV3 \354\225\274\352\267\274 \354\247\200\354\210\230.md" "b/lkhyun/202509/07 PGM LV3 \354\225\274\352\267\274 \354\247\200\354\210\230.md" new file mode 100644 index 00000000..5695de76 --- /dev/null +++ "b/lkhyun/202509/07 PGM LV3 \354\225\274\352\267\274 \354\247\200\354\210\230.md" @@ -0,0 +1,26 @@ +```java +import java.util.*; +class Solution { + static PriorityQueue pq = new PriorityQueue<>((a,b) -> Integer.compare(b,a)); + public long solution(int n, int[] works) { + long answer = 0; + for(int i : works){ + pq.offer(i); + } + for(int i=0;i 1){ + pq.offer(--cur); + } + }else{ + return 0; + } + } + for(int i : pq){ + answer += i*i; + } + return answer; + } +} +``` From 0f29f67c6043d26c4155453f3ce511468f89fbb1 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 7 Sep 2025 19:51:04 +0900 Subject: [PATCH 117/143] =?UTF-8?q?[20250907]=20BOJ=20/=20P5=20/=20?= =?UTF-8?q?=ED=8F=AD=ED=83=84=20=EB=8D=98=EC=A7=80=EB=8A=94=20=ED=83=9C?= =?UTF-8?q?=EC=98=81=EC=9D=B4=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \355\203\234\354\230\201\354\235\264.md" | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 "khj20006/202509/07 BOJ P5 \355\217\255\355\203\204 \353\215\230\354\247\200\353\212\224 \355\203\234\354\230\201\354\235\264.md" diff --git "a/khj20006/202509/07 BOJ P5 \355\217\255\355\203\204 \353\215\230\354\247\200\353\212\224 \355\203\234\354\230\201\354\235\264.md" "b/khj20006/202509/07 BOJ P5 \355\217\255\355\203\204 \353\215\230\354\247\200\353\212\224 \355\203\234\354\230\201\354\235\264.md" new file mode 100644 index 00000000..2f7a07fc --- /dev/null +++ "b/khj20006/202509/07 BOJ P5 \355\217\255\355\203\204 \353\215\230\354\247\200\353\212\224 \355\203\234\354\230\201\354\235\264.md" @@ -0,0 +1,93 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, M; + static long[][] h, c, s; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + h = new long[N+1][N+1]; + c = new long[N+1][N+1]; + s = new long[N+1][N+1]; + for(int i=0;i Date: Sun, 7 Sep 2025 21:01:15 +0900 Subject: [PATCH 118/143] =?UTF-8?q?[20250907]=20BOJ=20/=20G5=20/=20A?= =?UTF-8?q?=EC=99=80=20B=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../202509/07 BOJ G5 A\354\231\200 B.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "JHLEE325/202509/07 BOJ G5 A\354\231\200 B.md" diff --git "a/JHLEE325/202509/07 BOJ G5 A\354\231\200 B.md" "b/JHLEE325/202509/07 BOJ G5 A\354\231\200 B.md" new file mode 100644 index 00000000..cda2dbdd --- /dev/null +++ "b/JHLEE325/202509/07 BOJ G5 A\354\231\200 B.md" @@ -0,0 +1,33 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + String s = br.readLine(); + String t = br.readLine(); + + StringBuilder sb = new StringBuilder(); + sb.append(t); + + while (s.length() < sb.length()) { + char lastChar = sb.charAt(sb.length() - 1); + + sb.deleteCharAt(sb.length() - 1); + + if (lastChar == 'B') { + sb.reverse(); + } + } + + if (s.equals(sb.toString())) { + System.out.println(1); + } else { + System.out.println(0); + } + } +} + +``` From a967139c07395f7fb2126fcc17f431b2cad13b73 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sun, 7 Sep 2025 23:03:39 +0900 Subject: [PATCH 119/143] =?UTF-8?q?[20250907]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EB=8B=A4=EB=A6=AC=EB=A5=BC=20=EC=A7=80=EB=82=98=EB=8A=94=20?= =?UTF-8?q?=ED=8A=B8=EB=9F=AD=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\212\224 \355\212\270\353\237\255.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "suyeun84/202509/07 PGM LV2 \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.md" diff --git "a/suyeun84/202509/07 PGM LV2 \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.md" "b/suyeun84/202509/07 PGM LV2 \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.md" new file mode 100644 index 00000000..74bb5656 --- /dev/null +++ "b/suyeun84/202509/07 PGM LV2 \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.md" @@ -0,0 +1,37 @@ +```java +import java.util.*; + +class Solution { + public int solution(int bridge_length, int weight, int[] truck_weights) { + Queue q = new LinkedList(); + + for(int i=0;i Date: Sun, 7 Sep 2025 23:50:40 +0900 Subject: [PATCH 120/143] =?UTF-8?q?[20250907]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=A0=81=EB=A1=9D=EC=83=89=EC=95=BD=20/=20=EC=9D=B4=EC=9D=B8?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...01\353\241\235\354\203\211\354\225\275.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "LiiNi-coder/202509/07 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" diff --git "a/LiiNi-coder/202509/07 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" "b/LiiNi-coder/202509/07 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" new file mode 100644 index 00000000..4f2b6c2c --- /dev/null +++ "b/LiiNi-coder/202509/07 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" @@ -0,0 +1,60 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; + +public class Main { + private static final int[] dr = {-1, 0, 1, 0}; + private static final int[] dc = {0, 1, 0, -1}; + + public static void main(String[] args) throws IOException { + var br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + char[][] normal = new char[n][n]; + char[][] weak = new char[n][n]; + for (int i = 0; i < n; i++) { + String line = br.readLine(); + for (int j = 0; j < n; j++) { + char c = line.charAt(j); + normal[i][j] = c; + weak[i][j] = (c == 'G') ? 'R' : c; + } + } + int normalCount = countAreas(normal, n); + int weakCount = countAreas(weak, n); + + System.out.printf("%d %d\n", normalCount, weakCount); + } + private static int countAreas(char[][] map, int n) { + boolean[][] visited = new boolean[n][n]; + int count = 0; + var queue = new ArrayDeque(); + + for (int r = 0; r < n; r++) { + for (int c = 0; c < n; c++) { + if (visited[r][c]) + continue; + char color = map[r][c]; + count++; + visited[r][c] = true; + queue.offer(new int[] {r, c}); + while (!queue.isEmpty()) { + int[] now = queue.poll(); + for (int d = 0; d < 4; d++) { + int nr = now[0] + dr[d]; + int nc = now[1] + dc[d]; + if (nr >= 0 && nr < n && nc >= 0 && nc < n + && !visited[nr][nc] + && map[nr][nc] == color) { + visited[nr][nc] = true; + queue.offer(new int[] {nr, nc}); + } + } + } + } + } + return count; + } +} +``` From ecf8de0f40c0c550dd3c6a14fb9969630ef828e1 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sun, 7 Sep 2025 23:58:47 +0900 Subject: [PATCH 121/143] =?UTF-8?q?[20250907]=20BOJ=20/=20G4=20/=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=EC=97=86=EB=8A=94=20=EC=88=98=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...265 \354\227\206\353\212\224 \354\210\230" | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 "0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" diff --git "a/0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" "b/0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" new file mode 100644 index 00000000..a044da82 --- /dev/null +++ "b/0224LJH/202509/07 BOJ \354\244\221\353\263\265 \354\227\206\353\212\224 \354\210\230" @@ -0,0 +1,102 @@ +``` +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + + static int[] max = {0,9,98,987,9876,98765,987654,9876543,98765432,987654321}; + static int[] min = {0,1,12,123,1234,12345,123456,1234567,12345678,123456789}; + static int ans,target; + static int[] num; + + + static boolean[] used = new boolean[10]; + + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + + while(sc.hasNext()) { + target = sc.nextInt(); + ans = -1; + process(); + print(); + } + sc.close(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + ans = -1; + target = Integer.parseInt(br.readLine()); + + } + + public static void process() throws IOException { + if (target >= max[9]) { + ans = 0; + return; + } + + + int size = 0; + + for (int i = 8; i >= 0; i--) { + if (target / Math.pow(10, i) >= 1) { + size = i+1; + break; + } + } + + if (target >= max[size]) { + ans = min[size+1]; + return; + } + + num = new int[size]; + + + recur( 0, size); + + } + + private static void recur(int cur, int goal) { + if (ans != -1) return; + + if (cur == goal) { + int res = 0; + for (int i = 0; i < goal; i++) { + res*=10; + res+=num[i]; + } + ans = res; + return; + } + + int original = (target / (int)Math.pow(10, goal - cur - 1)) % 10; + int nNum = -1; + + for (int i = 1; i <= 9; i++) { + if (!used[i] && i >= original) { + used[i] = true; + num[cur] = i; + recur(cur+1, goal); + used[i] = false; + } + } + + + } + + + + + + + + public static void print() { + System.out.println(ans); + } +``` +} From 4490b5c56bd09b8237f1156bcf10a79e0c964518 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Mon, 8 Sep 2025 09:25:26 +0900 Subject: [PATCH 122/143] =?UTF-8?q?[20250908]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=9E=85=EA=B5=AD=EC=8B=AC=EC=82=AC=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...05\352\265\255\354\213\254\354\202\254.md" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "JHLEE325/202509/08 BOJ G5 \354\236\205\352\265\255\354\213\254\354\202\254.md" diff --git "a/JHLEE325/202509/08 BOJ G5 \354\236\205\352\265\255\354\213\254\354\202\254.md" "b/JHLEE325/202509/08 BOJ G5 \354\236\205\352\265\255\354\213\254\354\202\254.md" new file mode 100644 index 00000000..1339ddae --- /dev/null +++ "b/JHLEE325/202509/08 BOJ G5 \354\236\205\352\265\255\354\213\254\354\202\254.md" @@ -0,0 +1,41 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + int[] immigration = new int[n]; + + for (int i = 0; i < n; i++) { + immigration[i] = Integer.parseInt(br.readLine()); + } + + long left = 1; + long right = 1000000000 * (long)m; + long res = 0; + + while (left <= right) { + long mid = (left + right) / 2; + long people = 0; + for (int i = 0; i < n; i++) { + people += mid / immigration[i]; + if (people >= m) break; + } + if (people >= m) { + res = mid; + right = mid - 1; + } else { + left = mid + 1; + } + } + System.out.println(res); + } +} +``` From 0d89656a9818bcbeef13e40446d3fe1a9b21dc8c Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 8 Sep 2025 13:47:30 +0900 Subject: [PATCH 123/143] =?UTF-8?q?[20250908]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EC=B5=9C=EC=86=8C=20=EB=B9=84=EC=9A=A9=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \352\265\254\355\225\230\352\270\260.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "0224LJH/202509/08 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" diff --git "a/0224LJH/202509/08 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" "b/0224LJH/202509/08 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" new file mode 100644 index 00000000..9e664e66 --- /dev/null +++ "b/0224LJH/202509/08 BOJ \354\265\234\354\206\214\353\271\204\354\232\251 \352\265\254\355\225\230\352\270\260.md" @@ -0,0 +1,95 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + static int cityCnt, busCnt,start,goal; + static int[] distance; + static boolean[] visited; + static Node[] nodes; + static PriorityQueue pq = new PriorityQueue<>(); + + static class Node implements Comparable{ + int num; + Map costs = new HashMap<>(); + + public Node(int num) { + this.num = num; + } + + @Override + public int compareTo(Node o) { + return Integer.compare(distance[this.num], distance[o.num]); + } + } + + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + } + + public static void init() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cityCnt = Integer.parseInt(br.readLine()); + busCnt = Integer.parseInt(br.readLine()); + nodes = new Node[cityCnt+1]; + distance = new int[cityCnt+1]; + visited = new boolean[cityCnt+1]; + for (int i = 0; i <= cityCnt; i++) { + nodes[i] = new Node(i); + } + + for (int i = 0; i < busCnt; i++) { + StringTokenizer st = new StringTokenizer (br.readLine()); + int from = Integer.parseInt(st.nextToken()); + int to = Integer.parseInt(st.nextToken()); + int cost = Integer.parseInt(st.nextToken()); + + if (nodes[from].costs.containsKey(to)) { + int smaller = Math.min(cost, nodes[from].costs.get(to)); + nodes[from].costs.replace(to, smaller); + } else { + nodes[from].costs.put(to, cost); + } + + } + + StringTokenizer st = new StringTokenizer(br.readLine()); + start = Integer.parseInt(st.nextToken()); + goal = Integer.parseInt(st.nextToken()); + + Arrays.fill(distance, Integer.MAX_VALUE/2); + distance[start] = 0; + } + + public static void process() { + pq.add(nodes[start]); + + while(!pq.isEmpty()) { + Node n = pq.poll(); + if (visited[n.num]) continue; + visited[n.num] = true; + + for (int to: n.costs.keySet()) { + if(visited[to]) continue; + int cost = n.costs.get(to); + int nDistance = distance[n.num] + cost; + if (distance[to] > nDistance) { + distance[to] = nDistance; + pq.add(nodes[to]); + } + } + + } + + } + + public static void print() { + System.out.println(distance[goal]); + } +} +``` From 9e798a7887c9291c8b8a4d819f9d5b42d197f211 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Mon, 8 Sep 2025 20:32:39 +0900 Subject: [PATCH 124/143] =?UTF-8?q?[20250908]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=ED=96=89=EB=A0=AC=20=EA=B3=B1=EC=85=88=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\205\210 \354\210\234\354\204\234.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "Ukj0ng/202509/8 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" diff --git "a/Ukj0ng/202509/8 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" "b/Ukj0ng/202509/8 BOJ G3 \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..0813a699 --- /dev/null +++ "b/Ukj0ng/202509/8 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" @@ -0,0 +1,53 @@ +``` +import java.io.*; + import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[][] matrix, dp; + private static int N; + + public static void main(String[] args) throws IOException { + init(); + DP(); + + bw.write(dp[1][N] + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + matrix = new int[N+1][2]; + dp = new int[N+1][N+1]; + + for (int i = 1; i <= N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + matrix[i][0] = Integer.parseInt(st.nextToken()); + matrix[i][1] = Integer.parseInt(st.nextToken()); + } + } + + private static void DP() { + for (int i = 1; i < N; i++) { + dp[i][i+1] = matrix[i][0] * matrix[i][1] * matrix[i+1][1]; + } + + for (int len = 2; len <= N; len++) { + for (int start = 1; start <= N - len + 1; start++) { + int end = start + len - 1; + dp[start][end] = Integer.MAX_VALUE; + + for (int k = start; k < end; k++) { + int cost = dp[start][k] + dp[k+1][end] + + matrix[start][0] * matrix[k][1] * matrix[end][1]; + dp[start][end] = Math.min(dp[start][end], cost); + } + } + } + } +} +``` From f2aa798b5607554d0d4716fb65a093e06fc19dd7 Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 8 Sep 2025 20:42:43 +0900 Subject: [PATCH 125/143] =?UTF-8?q?[20250908]=20BOJ=20/=20P1=20/=20?= =?UTF-8?q?=ED=8A=B8=EB=A6=AC=EC=99=80=20XOR=20=EC=BF=BC=EB=A6=AC=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\231\200 XOR \354\277\274\353\246\254.md" | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 "khj20006/202509/08 BOJ P1 \355\212\270\353\246\254\354\231\200 XOR \354\277\274\353\246\254.md" diff --git "a/khj20006/202509/08 BOJ P1 \355\212\270\353\246\254\354\231\200 XOR \354\277\274\353\246\254.md" "b/khj20006/202509/08 BOJ P1 \355\212\270\353\246\254\354\231\200 XOR \354\277\274\353\246\254.md" new file mode 100644 index 00000000..99775e91 --- /dev/null +++ "b/khj20006/202509/08 BOJ P1 \355\212\270\353\246\254\354\231\200 XOR \354\277\274\353\246\254.md" @@ -0,0 +1,172 @@ +```java +import java.io.*; +import java.util.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) + nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, Q; + static int[][] seg, lazy; + static int[] in, out, rev, d, par; + static List[] graph; + static int order = 0; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + graph = new List[N+1]; + in = new int[N+1]; + out = new int[N+1]; + rev = new int[N+1]; + d = new int[N+1]; + par = new int[N+1]; + seg = new int[4*N][20]; + lazy = new int[4*N][20]; + for(int i=1;i<=N;i++) graph[i] = new ArrayList<>(); + for(int i=1;i0;) { + int o = io.nextInt(); + int x = io.nextInt(); + int y = io.nextInt(); + if(o == 1) { + int g = par[x] ^ y; + for(int k=0;k<20;k++) if((g & (1<>1; + init(s,m,n*2,x); + init(m+1,e,n*2+1,x); + seg[n][x] = seg[n*2][x] + seg[n*2+1][x]; + } + + static void prop(int s, int e, int n, int x) { + if(lazy[n][x] != 0) { + seg[n][x] = e-s+1 - seg[n][x]; + if(s != e) { + lazy[n*2][x] ^= 1; + lazy[n*2+1][x] ^= 1; + } + lazy[n][x] = 0; + } + } + + static void update(int s, int e, int l, int r, int n, int x) { + prop(s,e,n,x); + if(l>r || l>e || r>1; + update(s,m,l,r,n*2,x); + update(m+1,e,l,r,n*2+1,x); + seg[n][x] = seg[n*2][x] + seg[n*2+1][x]; + } + + static int find(int s, int e, int l, int r, int n, int x) { + prop(s,e,n,x); + if(l>r || l>e || r>1; + return find(s,m,l,r,n*2,x) + find(m+1,e,l,r,n*2+1,x); + } + +} +``` From bb78333a054636fff6692c21857be297922c78a4 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 8 Sep 2025 22:27:17 +0900 Subject: [PATCH 126/143] =?UTF-8?q?[20250908]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=95=8C=EA=B3=A0=EC=8A=A4=ED=8C=9F=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14\352\263\240\354\212\244\355\214\237.md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "lkhyun/202509/08 BOJ G4 \354\225\214\352\263\240\354\212\244\355\214\237.md" diff --git "a/lkhyun/202509/08 BOJ G4 \354\225\214\352\263\240\354\212\244\355\214\237.md" "b/lkhyun/202509/08 BOJ G4 \354\225\214\352\263\240\354\212\244\355\214\237.md" new file mode 100644 index 00000000..0de9bbfc --- /dev/null +++ "b/lkhyun/202509/08 BOJ G4 \354\225\214\352\263\240\354\212\244\355\214\237.md" @@ -0,0 +1,58 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,M; + static int[] di = {-1,1,0,0}; + static int[] dj = {0,0,-1,1}; + static int[][] matrix; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + + matrix = new int[N][M]; + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < M; j++) { + matrix[i][j] = Character.getNumericValue(line.charAt(j)); + } + } + bw.write(BFS()+""); + bw.close(); + } + public static int BFS(){ + ArrayDeque deq = new ArrayDeque<>(); + boolean[][] visited = new boolean[N][M]; + deq.offer(new int[]{0,0,0}); + visited[0][0] = true; + + while(!deq.isEmpty()){ + int[] cur = deq.poll(); + + if(cur[0] == N-1 && cur[1] == M-1) return cur[2]; + + for (int i = 0; i < 4; i++) { + int ni = cur[0] + di[i]; + int nj = cur[1] + dj[i]; + + if(ni<0 || ni>=N || nj<0 || nj>=M || visited[ni][nj]) continue; + + if(matrix[ni][nj] == 0){ + deq.offerFirst(new int[]{ni,nj,cur[2]}); + visited[ni][nj] = true; + }else{ + deq.offer(new int[]{ni,nj,cur[2]+1}); + visited[ni][nj] = true; + } + } + } + return 0; + } +} +``` From 6ed93c277396230c7d78470c7eb6494d03ecc842 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Mon, 8 Sep 2025 23:35:06 +0900 Subject: [PATCH 127/143] =?UTF-8?q?[20250908]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EB=8F=99=EC=A0=84=201=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../08 BOJ \353\217\231\354\240\204 1.md" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "LiiNi-coder/202509/08 BOJ \353\217\231\354\240\204 1.md" diff --git "a/LiiNi-coder/202509/08 BOJ \353\217\231\354\240\204 1.md" "b/LiiNi-coder/202509/08 BOJ \353\217\231\354\240\204 1.md" new file mode 100644 index 00000000..70af64c2 --- /dev/null +++ "b/LiiNi-coder/202509/08 BOJ \353\217\231\354\240\204 1.md" @@ -0,0 +1,35 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + private static BufferedReader br; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + int[] coins = new int[n]; + for (int i = 0; i < n; i++) { + coins[i] = Integer.parseInt(br.readLine()); + } + int[] dp = new int[k + 1]; + Arrays.fill(dp, 0); + + dp[0] = 1; + + for (int coin : coins) { + if (coin > k) continue; + for (int j = coin; j <= k; j++) { + dp[j] += dp[j - coin]; + } + } + + System.out.println(dp[k]); + } +} +``` From 8857ad0a793e65ccdbf770368bca2066a53e998b Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 8 Sep 2025 23:42:39 +0900 Subject: [PATCH 128/143] =?UTF-8?q?[20250908]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EB=A7=B5=20=EC=B5=9C=EB=8B=A8=EA=B1=B0?= =?UTF-8?q?=EB=A6=AC=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\213\250\352\261\260\353\246\254.md" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" diff --git "a/suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" "b/suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" new file mode 100644 index 00000000..39d39de7 --- /dev/null +++ "b/suyeun84/202509/08 PGM LV2 \352\262\214\354\236\204 \353\247\265 \354\265\234\353\213\250\352\261\260\353\246\254.md" @@ -0,0 +1,34 @@ +```java +import java.util.*; +class Solution { + public int solution(int[][] maps) { + + return bfs(maps); + } + public int bfs(int[][] maps) { + int n = maps.length; + int m = maps[0].length; + int[][] d = new int[][]{{1,0}, {-1,0}, {0,1}, {0,-1}}; + int[][] visited = new int[n][m]; + Queue q = new LinkedList<>(); + q.add(new int[]{0, 0, 1}); + visited[0][0] = 1; + while (!q.isEmpty()) { + int[] curr = q.poll(); + for (int[] move : d) { + int ny = curr[0] + move[0]; + int nx = curr[1] + move[1]; + if (0 > ny || ny >= n || 0 > nx || nx >= m || maps[ny][nx] == 0 || visited[ny][nx] != 0) { + continue; + } + visited[ny][nx] = curr[2] + 1; + q.add(new int[]{ny, nx, curr[2]+1}); + if (ny == n-1 && nx == m-1) { + return visited[ny][nx]; + } + } + } + return -1; + } +} +``` From c5fc2d319d6ff16469302cb200e3cd661d386d08 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Tue, 9 Sep 2025 08:02:47 +0900 Subject: [PATCH 129/143] =?UTF-8?q?[20250909]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=B2=BC=EB=9D=BD=EC=B9=98=EA=B8=B0=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" diff --git "a/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" "b/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" new file mode 100644 index 00000000..7f5b5cf5 --- /dev/null +++ "b/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" @@ -0,0 +1,29 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int t = Integer.parseInt(st.nextToken()); + + int[] dp = new int[t+1]; + + for(int i=0;i= k; j--) { + dp[j] = Math.max(dp[j], dp[j - k] + s); + } + } + + System.out.println(dp[t]); + } +} +``` From 05459d4bc0067af023e5078a4aa99e17a074ac9a Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Tue, 9 Sep 2025 08:03:20 +0900 Subject: [PATCH 130/143] =?UTF-8?q?Delete=20JHLEE325/202509/09=20BOJ=20G5?= =?UTF-8?q?=20=EB=B2=BC=EB=9D=BD=EC=B9=98=EA=B8=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.md" | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 "JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" diff --git "a/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" "b/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" deleted file mode 100644 index 7f5b5cf5..00000000 --- "a/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" +++ /dev/null @@ -1,29 +0,0 @@ -```java -import java.io.*; -import java.util.*; - -public class Main { - - public static void main(String[] args) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - StringTokenizer st = new StringTokenizer(br.readLine()); - - int n = Integer.parseInt(st.nextToken()); - int t = Integer.parseInt(st.nextToken()); - - int[] dp = new int[t+1]; - - for(int i=0;i= k; j--) { - dp[j] = Math.max(dp[j], dp[j - k] + s); - } - } - - System.out.println(dp[t]); - } -} -``` From 4af24259f4068b78ab16b4247f8ca71ded14984b Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Tue, 9 Sep 2025 08:04:11 +0900 Subject: [PATCH 131/143] =?UTF-8?q?[20250909]=20BOJ=20/=20G5=20/=20?= =?UTF-8?q?=EB=B2=BC=EB=9D=BD=EC=B9=98=EA=B8=B0=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.md" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" diff --git "a/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" "b/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" new file mode 100644 index 00000000..7f5b5cf5 --- /dev/null +++ "b/JHLEE325/202509/09 BOJ G5 \353\262\274\353\235\275\354\271\230\352\270\260.md" @@ -0,0 +1,29 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int t = Integer.parseInt(st.nextToken()); + + int[] dp = new int[t+1]; + + for(int i=0;i= k; j--) { + dp[j] = Math.max(dp[j], dp[j - k] + s); + } + } + + System.out.println(dp[t]); + } +} +``` From da1bfa5bee3572c96f6a1dcabb789e35c477b382 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Tue, 9 Sep 2025 09:49:23 +0900 Subject: [PATCH 132/143] =?UTF-8?q?[20250909]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=ED=95=A9=EC=B9=98=EA=B8=B0=20/=20?= =?UTF-8?q?=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \355\225\251\354\271\230\352\270\260.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "Ukj0ng/202509/9 BOJ G3 \355\214\214\354\235\274 \355\225\251\354\271\230\352\270\260.md" diff --git "a/Ukj0ng/202509/9 BOJ G3 \355\214\214\354\235\274 \355\225\251\354\271\230\352\270\260.md" "b/Ukj0ng/202509/9 BOJ G3 \355\214\214\354\235\274 \355\225\251\354\271\230\352\270\260.md" new file mode 100644 index 00000000..bfbbd353 --- /dev/null +++ "b/Ukj0ng/202509/9 BOJ G3 \355\214\214\354\235\274 \355\225\251\354\271\230\352\270\260.md" @@ -0,0 +1,53 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[][] dp; + private static int[] file, sum; + private static int K; + + public static void main(String[] args) throws IOException { + int T = Integer.parseInt(br.readLine()); + while (T-- > 0) { + init(); + DP(); + bw.write(dp[1][K] + "\n"); + } + bw.flush(); + bw.close(); + br.close(); + + } + + private static void init() throws IOException { + K = Integer.parseInt(br.readLine()); + StringTokenizer st = new StringTokenizer(br.readLine()); + + file = new int[K+1]; + sum = new int[K+1]; + dp = new int[K+1][K+1]; + + for (int i = 1; i <= K; i++) { + file[i] = Integer.parseInt(st.nextToken()); + sum[i] = sum[i-1] + file[i]; + } + } + + private static void DP() { + for (int i = 2; i <= K; i++) { + for (int j = 1; j <= K-i+1; j++) { + int k = i+j-1; + dp[j][k] = Integer.MAX_VALUE; + + for (int l = j; l < k; l++) { + int cost = dp[j][l] + dp[l+1][k] + sum[k] - sum[j-1]; + dp[j][k] = Math.min(cost, dp[j][k]); + } + } + } + } +} +``` From 5eedf17295752d843bf24c9af65207c66648b001 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 9 Sep 2025 11:23:57 +0900 Subject: [PATCH 133/143] =?UTF-8?q?[20250909]=20BOJ=20/=20P2=20/=20Double?= =?UTF-8?q?=20Up=202=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202509/09 BOJ P2 Double Up 2.md | 174 +++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 khj20006/202509/09 BOJ P2 Double Up 2.md diff --git a/khj20006/202509/09 BOJ P2 Double Up 2.md b/khj20006/202509/09 BOJ P2 Double Up 2.md new file mode 100644 index 00000000..8d959ddf --- /dev/null +++ b/khj20006/202509/09 BOJ P2 Double Up 2.md @@ -0,0 +1,174 @@ +```java +import java.io.*; +import java.util.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) + nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, M; + static int[] next, root, indeg; + static long[] cnt, origin; + static List> cycles; + static boolean[] isCycle; + + static int f(int x) {return x==root[x] ? x : (root[x]=f(root[x]));} + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + next = new int[M]; + origin = new long[M]; + root = new int[M]; + cnt = new long[M]; + indeg = new int[M]; + for(int i=0;i(); + boolean[] vis = new boolean[M]; + boolean[] vvis = new boolean[M]; + int[] par = new int[M]; + for(int i=0;i list = new ArrayList<>(); + int r = next[n]; + list.add(r); + while(n != r) { + list.add(n); + n = par[n]; + } + cycles.add(list); + } + + isCycle = new boolean[M]; + for(List list : cycles) { + for(int i:list) isCycle[i] = true; + } + + Queue q = new ArrayDeque<>(); + for(int i=0;i list : cycles) { + long sum = 0, s = 0; + int zeroCnt = 0; + for(int i=0;i S) ans = res; + else ans = Math.min(ans, res); + S = s; + continue; + } + + long res = sum; + for(int i=0;i S) ans = res; + else ans = Math.min(ans, res); + S = s; + } + + io.write(S + " " + ans + "\n"); + + io.close(); + + } + +} +``` From 1a1215a273d8b5e7ca1827d89e879f73a1e9646b Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Tue, 9 Sep 2025 13:31:03 +0900 Subject: [PATCH 134/143] =?UTF-8?q?[20250909]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=A0=80=20=ED=86=B5=EC=8B=A0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\240\200 \355\206\265\354\213\240.md" | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 "0224LJH/202509/09 BOJ \353\240\210\354\235\264\354\240\200 \355\206\265\354\213\240.md" diff --git "a/0224LJH/202509/09 BOJ \353\240\210\354\235\264\354\240\200 \355\206\265\354\213\240.md" "b/0224LJH/202509/09 BOJ \353\240\210\354\235\264\354\240\200 \355\206\265\354\213\240.md" new file mode 100644 index 00000000..a271e232 --- /dev/null +++ "b/0224LJH/202509/09 BOJ \353\240\210\354\235\264\354\240\200 \355\206\265\354\213\240.md" @@ -0,0 +1,111 @@ +```java + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + static char[][] arr; + static int[][] dp; + static int width,height,goalY,goalX , curY,curX, curCnt,curDir,ans; + static boolean success = false; + + static Queue q = new LinkedList<>(); + static int[] dy = {-1,0,1,0}; + static int[] dx = {0,1,0,-1}; + + static final char WALL = '*'; + static final char GOAL = 'C'; + + + static class Point{ + int y,x,dir; + + public Point(int y,int x,int dir) { + this.y = y; + this.x = x; + this.dir = dir; + } + } + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + } + + public static void init() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + width = Integer.parseInt(st.nextToken()); + height = Integer.parseInt(st.nextToken()); + arr = new char[height][width]; + dp = new int[height][width]; + boolean first = true; + + for (int i = 0 ; i < height; i++) { + String input = br.readLine(); + arr[i] = input.toCharArray(); + Arrays.fill(dp[i], Integer.MAX_VALUE/2); + for (int j = 0; j < width; j++) { + if (arr[i][j] == GOAL && first) { + first = false; + dp[i][j] = -1; + for (int k = 0; k < 4; k++) q.add(new Point(i,j,k)); + } else if (arr[i][j] == GOAL) { + goalY = i; + goalX = j; + } else if (arr[i][j] == WALL) { + dp[i][j] = -1; + } + } + } + + } + + public static void process() { + while(!q.isEmpty()) { + int qLen = q.size(); + for (int i = 0; i < qLen; i++) { + unitProcess(); + } + } + } + + + public static void unitProcess() { + Point p = q.poll(); + for (int j = 0; j < 4; j++) { + curY = p.y; + curX = p.x; + curDir = j; + curCnt = dp[curY][curX] +1 ; + if (curDir == p.dir) continue; + + while(true) { + curY += dy[curDir]; + curX += dx[curDir]; + if (curY == goalY && curX == goalX) { + ans = curCnt; + } + + if (curY >= height || curY < 0 || curX >= width || curX < 0 ) break; + if (arr[curY][curX] == WALL) break; + if (dp[curY][curX] <= curCnt) continue; + + dp[curY][curX] = curCnt; + q.add(new Point(curY,curX,j)); + + + + } + + } + } + + public static void print() { + System.out.println(dp[goalY][goalX]); + } +} +``` From 83c0c7949358db5b9f5fcb6395d150838d201ffb Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 9 Sep 2025 19:40:43 +0900 Subject: [PATCH 135/143] =?UTF-8?q?[20250909]=20BOJ=20/=20G2=20/=20?= =?UTF-8?q?=EC=87=BC=ED=95=91=EB=AA=B0=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 \354\207\274\355\225\221\353\252\260.md" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "lkhyun/202509/09 BOJ G2 \354\207\274\355\225\221\353\252\260.md" diff --git "a/lkhyun/202509/09 BOJ G2 \354\207\274\355\225\221\353\252\260.md" "b/lkhyun/202509/09 BOJ G2 \354\207\274\355\225\221\353\252\260.md" new file mode 100644 index 00000000..759cd2ff --- /dev/null +++ "b/lkhyun/202509/09 BOJ G2 \354\207\274\355\225\221\353\252\260.md" @@ -0,0 +1,56 @@ +```java + +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + static int N,K; + static PriorityQueue in; + static PriorityQueue out; + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + in = new PriorityQueue<>((a,b) -> { + if(a[0] == b[0]){ //시간이 같으면 + return Long.compare(a[1], b[1]); //적은 번호에 해당하는 곳 + }else{ + return Long.compare(a[0], b[0]); + } + }); + out = new PriorityQueue<>((a,b) -> { + if(a[0] == b[0]){ //시간이 같으면 + return Long.compare(b[1], a[1]); //큰 번호에 해당하는 곳 + }else{ + return Long.compare(a[0], b[0]); + } + }); + for (int i = 1; i <= K; i++) { + in.offer(new long[]{0,i}); + } + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int num = Integer.parseInt(st.nextToken()); + int time = Integer.parseInt(st.nextToken()); + long[] insert = in.poll(); + insert[0] += time; + in.offer(insert); + out.offer(new long[]{insert[0],insert[1],num}); + } + + long ans = 0; + for (int i = 1; i <= N; i++) { + ans += i*out.poll()[2]; + } + bw.write(ans+""); + bw.close(); + } + +} +``` From 5da1f3d8a654affd922c3eb719659567f6ef7c0b Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 9 Sep 2025 21:10:33 +0900 Subject: [PATCH 136/143] =?UTF-8?q?[20250909]=20PGM=20/=20LV2=20/=20[1?= =?UTF-8?q?=EC=B0=A8]=20=ED=94=84=EB=A0=8C=EC=A6=884=EB=B8=94=EB=A1=9D=20/?= =?UTF-8?q?=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\246\2104\353\270\224\353\241\235.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" diff --git "a/suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" "b/suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" new file mode 100644 index 00000000..986e8d35 --- /dev/null +++ "b/suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" @@ -0,0 +1,74 @@ + ```java +import java.util.*; +class Solution { + static int[][] dir = new int[][]{{0,0}, {0, 1}, {1,0}, {1,1}}; + static int M, N, answer = 0; + static char[][] map; + public int solution(int m, int n, String[] board) { + M = m; + N = n; + map = new char[M][N]; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + map[i][j] = board[i].charAt(j); + } + } + boolean flag = true; + while (flag) { + flag = check(); + } + return answer; + } + // 없앨 수 있는 block 찾기 + private boolean check() { + boolean[][] remove = new boolean[M][N]; + boolean flag = false; + for (int i = 0; i < M-1; i++) { + for (int j = 0; j < N-1; j++) { + char curr = map[i][j]; + if (curr == '0') continue; + if (curr == map[i+1][j] && curr == map[i][j+1] && curr == map[i+1][j+1]) { + for (int[] d : dir) { + int ny = i + d[0]; + int nx = j + d[1]; + if (!remove[ny][nx]) answer++; + remove[ny][nx] = true; + } + flag = true; + } + } + } + if (flag) move(remove); + return flag; + } + + private void move(boolean[][] remove) { + for (int j = 0; j < N; j++) { // 각 열마다 + Stack stack = new Stack<>(); + + for (int i = 0; i < M; i++) { + if (!remove[i][j] && map[i][j] != '0') { + stack.push(map[i][j]); + } + } + + for (int i = M - 1; i >= 0; i--) { + if (!stack.isEmpty()) { + map[i][j] = stack.pop(); + } else { + map[i][j] = '0'; + } + } + } + } + + + class Point { + int y, x; + public Point(int y, int x) { + this.y = y; + this.x = x; + } + } +} +``` From 507f1b184ad624a5e515b0da023fcba01e23ebdc Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Tue, 9 Sep 2025 23:01:53 +0900 Subject: [PATCH 137/143] =?UTF-8?q?[20250909]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=EC=A0=84=EA=B5=AC=EC=99=80=20=EC=8A=A4=EC=9C=84=EC=B9=98=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\212\244\354\234\204\354\271\230.md" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "LiiNi-coder/202509/09 BOJ \354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.md" diff --git "a/LiiNi-coder/202509/09 BOJ \354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.md" "b/LiiNi-coder/202509/09 BOJ \354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.md" new file mode 100644 index 00000000..3a18e79d --- /dev/null +++ "b/LiiNi-coder/202509/09 BOJ \354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.md" @@ -0,0 +1,46 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; + +public class Main { + public static void main(String[] args) throws IOException { + var br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + char[] src = br.readLine().toCharArray(); + char[] dst = br.readLine().toCharArray(); + int answer = process(Arrays.copyOf(src, n), dst, false); + answer = Math.min(answer, process(Arrays.copyOf(src, n), dst, true)); + + System.out.println(answer == Integer.MAX_VALUE ? -1 : answer); + } + static int process(char[] s, char[] target, boolean firstPress) { + int count = 0; + // 첫번째 토글로 그리디 분기 + if (firstPress) { + toggle(s, 0); + toggle(s, 1); + count++; + } + for (int i = 1; i < s.length; i++) { + if (s[i - 1] != target[i - 1]) { + toggle(s, i - 1); + toggle(s, i); + if (i + 1 < s.length) + toggle(s, i + 1); + count++; + } + } + + for (int i = 0; i < s.length; i++) { + if (s[i] != target[i]) return Integer.MAX_VALUE; + } + return count; + } + + static void toggle(char[] arr, int i) { + arr[i] = arr[i] == '0' ? '1' : '0'; + } +} +``` From 05ff9beb6bbae4f05e6d1f9c68f56a4ddf46ba15 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Wed, 10 Sep 2025 08:16:54 +0900 Subject: [PATCH 138/143] =?UTF-8?q?[20250910]=20BOJ=20/=20G3=20/=20?= =?UTF-8?q?=ED=83=9D=EB=B0=B0=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../10 BOJ G3 \355\203\235\353\260\260.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" diff --git "a/JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" "b/JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" new file mode 100644 index 00000000..ba33f6a0 --- /dev/null +++ "b/JHLEE325/202509/10 BOJ G3 \355\203\235\353\260\260.md" @@ -0,0 +1,62 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static final int INF = 987654321; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + + int[][] dist = new int[n][n]; + int[][] next = new int[n][n]; + + for (int i = 0; i < n; i++) { + Arrays.fill(dist[i], INF); + dist[i][i] = 0; + Arrays.fill(next[i], -1); + } + + for (int i = 0; i < m; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()) - 1; + int b = Integer.parseInt(st.nextToken()) - 1; + int c = Integer.parseInt(st.nextToken()); + + if (c < dist[a][b]) { + dist[a][b] = c; + dist[b][a] = c; + next[a][b] = b; + next[b][a] = a; + } + } + + for (int k = 0; k < n; k++) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (dist[i][j] > dist[i][k] + dist[k][j]) { + dist[i][j] = dist[i][k] + dist[k][j]; + next[i][j] = next[i][k]; + } + } + } + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i == j) sb.append("- "); + else sb.append(next[i][j] + 1).append(" "); + } + sb.append("\n"); + } + + System.out.print(sb); + } +} + +``` From 8053dca62d9a92fc8777fbd24efbd803f1b2ec8b Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:35:57 +0900 Subject: [PATCH 139/143] =?UTF-8?q?[20250910]=20BOJ=20/=20G1=20/=20?= =?UTF-8?q?=EC=A0=9C=EA=B3=B1=20=E3=84=B4=E3=84=B4=EC=88=98=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \343\204\264\343\204\264\354\210\230.md" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "lkhyun/202509/10 BOJ G1 \354\240\234\352\263\261 \343\204\264\343\204\264\354\210\230.md" diff --git "a/lkhyun/202509/10 BOJ G1 \354\240\234\352\263\261 \343\204\264\343\204\264\354\210\230.md" "b/lkhyun/202509/10 BOJ G1 \354\240\234\352\263\261 \343\204\264\343\204\264\354\210\230.md" new file mode 100644 index 00000000..229f6fe7 --- /dev/null +++ "b/lkhyun/202509/10 BOJ G1 \354\240\234\352\263\261 \343\204\264\343\204\264\354\210\230.md" @@ -0,0 +1,44 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static StringBuilder sb = new StringBuilder(); + static long min,max; + static List squares; + static long cnt; + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + min = Long.parseLong(st.nextToken()); + max = Long.parseLong(st.nextToken()); + squares = new ArrayList<>(); + cnt = max-min+1; + + long temp = 2; + while(temp*temp<=max){ //제곱수 저장 + squares.add(temp*temp); + temp++; + } + + Set s = new HashSet<>(); + + for (long cur : squares) { + long init = min/cur; + long result = cur*init++; + if(min%cur == 0) s.add(result); + result = cur*init; + while(result<=max){ + s.add(result); + result = ++init * cur; + } + } + + bw.write((cnt - s.size())+""); + bw.close(); + } + +} +``` From 3a01d85a29655950802bed248897adef5ba5336a Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 10 Sep 2025 20:20:43 +0900 Subject: [PATCH 140/143] =?UTF-8?q?[20250910]=20BOJ=20/=20D5=20/=20?= =?UTF-8?q?=EB=B8=94=EB=9E=99=ED=99=80=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5 \353\270\224\353\236\231\355\231\200.md" | 407 ++++++++++++++++++ 1 file changed, 407 insertions(+) create mode 100644 "khj20006/202509/10 BOJ D5 \353\270\224\353\236\231\355\231\200.md" diff --git "a/khj20006/202509/10 BOJ D5 \353\270\224\353\236\231\355\231\200.md" "b/khj20006/202509/10 BOJ D5 \353\270\224\353\236\231\355\231\200.md" new file mode 100644 index 00000000..11d1754d --- /dev/null +++ "b/khj20006/202509/10 BOJ D5 \353\270\224\353\236\231\355\231\200.md" @@ -0,0 +1,407 @@ +## Python +```python +import sys +from functools import cmp_to_key +input = sys.stdin.readline + +def ccw(a,b,c): + ax, ay = a + bx, by = b + cx, cy = c + res = ax*by + bx*cy + cx*ay - (ax*cy + bx*ay + cx*by); + if res > 0: + return 1 + if res < 0: + return -1 + return 0 + +def cmpe(a, b): + ax, ay = a + bx, by = b + anum = 10 + bnum = 10 + if ax == 0: + if ay > 0: + anum = 2 + else: + anum = 6 + elif ay == 0: + if ax > 0: + anum = 0 + else: + anum = 4 + else: + if ax > 0: + if ay > 0: + anum = 1 + else: + anum = 7 + else: + if ay > 0: + anum = 3 + else: + anum = 5 + + if bx == 0: + if by > 0: + bnum = 2 + else: + bnum = 6 + elif by == 0: + if bx > 0: + bnum = 0 + else: + bnum = 4 + else: + if bx > 0: + if by > 0: + bnum = 1 + else: + bnum = 7 + else: + if by > 0: + bnum = 3 + else: + bnum = 5 + + if anum == bnum: + return -ccw([0,0], a, b) + return anum-bnum + + + +N, M, K = map(int, input().split()) +X, Y = map(int, input().split()) + +hull = [] +for i in range(N): + a, b = map(int, input().split()) + a -= X + b -= Y + hull.append([a,b]) + +tmp = [] +for i in range(M): + a, b = map(int, input().split()) + a -= X + b -= Y + if a == 0 and b == 0: + K -= 1 + else: + tmp.append([a,b]) + +if K <= 0: + print(0) + exit(0) + +arr = sorted(tmp, key=cmp_to_key(cmpe)) + +t = [] +e = 0 +while e < N: + p = (e+N-1)%N + r1 = ccw([0,0], hull[p], arr[0]) + r2 = ccw([0,0], arr[0], hull[e]) + if r1 > 0 and r2 >= 0: + break + e+=1 +e%=N + +for g in arr: + x, y = g + while ccw([0,0], hull[(e+N-1)%N], [x,y]) <= 0 or ccw([0,0], [x,y], hull[e]) < 0: + e = (e+1)%N + l = 0 + r = 5000000000000000000 + m = (l+r)//2 + while l points; + + // 1 : counter-clockwise + // -1 : clockwise + // 0 : line + static int ccw(Point a, Point b, Point c) { + BigInteger ax = new BigInteger(Long.toString(a.x)); + BigInteger ay = new BigInteger(Long.toString(a.y)); + BigInteger bx = new BigInteger(Long.toString(b.x)); + BigInteger by = new BigInteger(Long.toString(b.y)); + BigInteger cx = new BigInteger(Long.toString(c.x)); + BigInteger cy = new BigInteger(Long.toString(c.y)); + BigInteger res = ax.multiply(by) + .subtract(bx.multiply(ay)) + .add(bx.multiply(cy)) + .subtract(cx.multiply(by)) + .add(cx.multiply(ay)) + .subtract(ax.multiply(cy)); + + return res.compareTo(new BigInteger("0")); + } + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + K = io.nextInt(); + + Point[] hull = new Point[N]; + List lower = new ArrayList<>(); + List upper = new ArrayList<>(); + long X = io.nextLong(); + long Y = io.nextLong(); + for(int i=0;i 0) upper.add(point); + else lower.add(point); + } + + // early stopping + if(K <= 0) { + io.write("0"); + return; + } + + Collections.sort(upper, (a,b) -> -ccw(new Point(0,0), a, b)); + Collections.sort(lower, (a,b) -> -ccw(new Point(0,0), a, b)); + points = new ArrayList<>(); + for(Point point : upper) points.add(point); + for(Point point : lower) points.add(point); + + List time = new ArrayList<>(); + int e = 0; + while(e < N) { + int p = (e+N-1)%N; + int r1 = ccw(new Point(0,0), hull[p], points.get(0)); + int r2 = ccw(new Point(0,0), points.get(0), hull[e]); + if(r1 > 0 && r2 >= 0) break; + e++; + } + e %= N; + + for(int i=0;i>1; + while(l>1; + } + time.add(m); + } + + Collections.sort(time); + io.write(time.get(K-1) + "\n"); + + io.close(); + + } + +} +``` + +## C++ +```cpp +#include +using namespace std; +using ll = long long; + +int N, M, K; +vector> hull, arr; + +int ccw(pair<__int128, __int128> a, pair<__int128, __int128> b, pair<__int128, __int128> c) { + auto [ax, ay] = a; + auto [bx, by] = b; + auto [cx, cy] = c; + __int128 res = (__int128)ax*(__int128)by + (__int128)bx*(__int128)cy + (__int128)cx*(__int128)ay - ((__int128)ax*(__int128)cy + (__int128)bx*(__int128)ay + (__int128)cx*(__int128)by); + if(res > 0) return 1; + if(res < 0) return -1; + return 0; +} + +int main() { + cin.tie(0)->sync_with_stdio(0); + cout.tie(0); + + ll X, Y; + cin>>N>>M>>K>>X>>Y; + hull.resize(N); + for(auto &[a,b]:hull) { + ll c,d; + cin>>c>>d; + a = c-X, b = d-Y; + } + for(int i=0;i>c>>d; + __int128 x = c-X, y = d-Y; + if(!x && !y) K--; + else arr.emplace_back(x,y); + } + if(K <= 0) return cout<<0,0; + + sort(arr.begin(), arr.end(), [](auto a, auto b) -> bool { + auto [ax, ay] = a; + auto [bx, by] = b; + int anum, bnum; + if(ax == 0) { + if(ay > 0) anum = 2; + else anum = 6; + } + else if(ay == 0) { + if(ax > 0) anum = 0; + else anum = 4; + } + else { + if(ax > 0) { + if(ay > 0) anum = 1; + else anum = 7; + } + else { + if(ay > 0) anum = 3; + else anum = 5; + } + } + + if(bx == 0) { + if(by > 0) bnum = 2; + else bnum = 6; + } + else if(by == 0) { + if(bx > 0) bnum = 0; + else bnum = 4; + } + else { + if(bx > 0) { + if(by > 0) bnum = 1; + else bnum = 7; + } + else { + if(by > 0) bnum = 3; + else bnum = 5; + } + } + + if(anum == bnum) return ccw({0,0}, a, b) > 0; + return anum < bnum; + }); + + vector<__int128> t; + int e = 0; + while(e < N) { + int p = (e+N-1)%N; + int r1 = ccw({0,0}, hull[p], arr[0]); + int r2 = ccw({0,0}, arr[0], hull[e]); + if(r1 > 0 && r2 >= 0) break; + e++; + } + e %= N; + + for(auto [x,y]:arr) { + while(ccw({0,0}, hull[(e+N-1)%N], {x,y}) <= 0 || ccw({0,0}, {x,y}, hull[e]) < 0) e = (e+1)%N; + __int128 l = 0, r = (__int128)5e18, m = (l+r)>>1; + while(l>1; + } + t.push_back(m); + } + + sort(t.begin(), t.end()); + cout<<(ll)t[K-1]; + +} +``` From 16413d568eabb075ec5f1b8233572518c158905e Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 10 Sep 2025 21:32:26 +0900 Subject: [PATCH 141/143] =?UTF-8?q?[20250910]=20PGM=20/=20LV2=20/=20?= =?UTF-8?q?=EB=A7=88=EB=B2=95=EC=9D=98=20=EC=97=98=EB=A6=AC=EB=B2=A0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\353\262\240\354\235\264\355\204\260.md" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "suyeun84/202509/10 PGM LV2 \353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.md" diff --git "a/suyeun84/202509/10 PGM LV2 \353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.md" "b/suyeun84/202509/10 PGM LV2 \353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.md" new file mode 100644 index 00000000..3a584ff7 --- /dev/null +++ "b/suyeun84/202509/10 PGM LV2 \353\247\210\353\262\225\354\235\230 \354\227\230\353\246\254\353\262\240\354\235\264\355\204\260.md" @@ -0,0 +1,24 @@ +```java +class Solution { + public int solution(int storey) { + int answer = 0; + while(storey > 0) { + int temp = storey % 10; + storey /= 10; + + if (temp > 5) { + answer += (10-temp); + storey++; + } else if (temp < 5) { + answer += temp; + } else if (storey % 10 >= 5) { + answer += 5; + storey++; + } else { + answer += 5; + } + } + return answer; + } +} +``` From 5910a38bfe30373c30ec2be1eeded86b731b569e Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Wed, 10 Sep 2025 23:33:38 +0900 Subject: [PATCH 142/143] =?UTF-8?q?[20250910]=20BOJ=20/=20G4=20/=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20=EB=B8=94=EB=A1=9D=20=EC=8C=93=EA=B8=B0=20?= =?UTF-8?q?/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\241\235 \354\214\223\352\270\260.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "0224LJH/202509/10 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" diff --git "a/0224LJH/202509/10 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" "b/0224LJH/202509/10 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" new file mode 100644 index 00000000..2e85f0cf --- /dev/null +++ "b/0224LJH/202509/10 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" @@ -0,0 +1,72 @@ +```java +import java.io.IOException; +import java.io.*; +import java.util.*; + + +public class Main { + static int studentCnt, numCnt,goal; + static int[][] arr; + static int[] dp; + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + public static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + studentCnt = Integer.parseInt(st.nextToken()); + numCnt =Integer.parseInt(st.nextToken()); + goal = Integer.parseInt(st.nextToken()); + + dp = new int[goal+1]; + + arr = new int[studentCnt][numCnt]; + for (int i = 0; i < studentCnt; i++) { + st = new StringTokenizer(br.readLine()); + int idx = 0; + while (st.hasMoreTokens()) { + arr[i][idx++] = Integer.parseInt(st.nextToken()); + } + } + + } + + public static void process() throws IOException { + dp[0] = 1; + for (int i = 0; i < studentCnt; i++) { + int[] temp = new int[goal+1]; + + for (int j = 0 ; j < numCnt; j++) { + int num = arr[i][j]; + if (num == 0) continue; + for (int k = 0 ; k <= goal-num; k++) { + temp[k+num] += dp[k]; + } + + } + + for (int j = 0; j <= goal; j++) { + dp[j] += temp[j]; + dp[j] %= 10007; + } + } + + } + + + + public static void print() { + for (int j = 0; j <= goal; j++) { + System.out.print(dp[j] + " "); + } + System.out.println(); + System.out.println(dp[goal]); + } +} + +``` From 02b42aae33acacc308422f5ed2779c799f202285 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Wed, 10 Sep 2025 23:46:30 +0900 Subject: [PATCH 143/143] =?UTF-8?q?[20250910]=20BOJ=20/=20G2=20/=20?= =?UTF-8?q?=EC=A4=91=EC=95=99=EA=B0=92=20=EA=B5=AC=ED=95=98=EA=B8=B0=20/?= =?UTF-8?q?=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...231\352\260\222 \352\265\254\355\225\230\352\270\260.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" "b/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" index d5c7f4ab..22a7b336 100644 --- "a/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" +++ "b/zinnnn37/202509/10 BOJ G2 \354\244\221\354\225\231\352\260\222 \352\265\254\355\225\230\352\270\260.md" @@ -26,6 +26,7 @@ public class BJ_2696_중앙값_구하기 { while (T-- > 0) { M = Integer.parseInt(br.readLine()); + bw.write((M / 2 + 1) + "\n"); s = ""; minq = new PriorityQueue<>(); @@ -47,11 +48,10 @@ public class BJ_2696_중앙값_구하기 { } if (i % 2 == 0) { - s += maxq.peek() + (i > 2 && (i + 2) % 20 == 0 ? "\n" : " "); + bw.write(maxq.peek() + (i > 2 && (i + 2) % 20 == 0 ? "\n" : " ")); } } - bw.write(maxq.size() + "\n"); - bw.write(s + "\n"); + bw.write("\n"); } bw.flush(); bw.close();