From eee5360d60ba117f12f682831fcd3d243019e2ce Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 8 May 2025 09:35:25 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[BOJ-17951]=20=ED=9D=A9=EB=82=A0=EB=A6=AC?= =?UTF-8?q?=EB=8A=94=20=EC=8B=9C=ED=97=98=EC=A7=80=20=EC=86=8D=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=82=B4=20=ED=8F=89=EC=A0=90=EC=9D=B4=20=EB=8A=90?= =?UTF-8?q?=EA=BB=B4=EC=A7=84=EA=B1=B0=EC=95=BC.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\354\247\204\352\261\260\354\225\274.md" | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-17951] \355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.md" diff --git "a/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-17951] \355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.md" "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-17951] \355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.md" new file mode 100644 index 00000000..76c526de --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-17951] \355\235\251\353\202\240\353\246\254\353\212\224 \354\213\234\355\227\230\354\247\200 \354\206\215\354\227\220\354\204\234 \353\202\264 \355\217\211\354\240\220\354\235\264 \353\212\220\352\273\264\354\247\204\352\261\260\354\225\274.md" @@ -0,0 +1,99 @@ +# JAVA + +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N, K; + static int[] A; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + K = nextInt(); + A = new int[N]; + for(int i=0;i>1; + while(s= m) { + sum = 0; + cnt++; + } + } + if(cnt > K) s = m; + else e = m-1; + m = (s+e+1)>>1; + } + bw.write(m + "\n"); + + } + +} +``` + +# CPP + +```cpp +#include +#include +using namespace std; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + int N, K; + cin >> N >> K; + vector A(N); + for (int &i : A) cin >> i; + + int s = 0, e = 2000000, m = (s + e + 1) >> 1; + while (s < e) { + int cnt = 1, sum = 0; + for (int i : A) { + sum += i; + if (sum >= m) cnt++, sum = 0; + } + if (cnt > K) s = m; + else e = m - 1; + m = (s + e + 1) >> 1; + } + cout << m; + +} +``` From 64ca1069f47145c3ec3daa585fa5d5d4ca1232ae Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 8 May 2025 12:27:20 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[BOJ-15653]=20=EA=B5=AC=EC=8A=AC=20?= =?UTF-8?q?=ED=83=88=EC=B6=9C=204.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\212\254 \355\203\210\354\266\234 4.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-15653] \352\265\254\354\212\254 \355\203\210\354\266\234 4.md" diff --git "a/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-15653] \352\265\254\354\212\254 \355\203\210\354\266\234 4.md" "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-15653] \352\265\254\354\212\254 \355\203\210\354\266\234 4.md" new file mode 100644 index 00000000..29c64475 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-15653] \352\265\254\354\212\254 \355\203\210\354\266\234 4.md" @@ -0,0 +1,60 @@ +# CPP +```cpp +#include +#include +#include +using namespace std; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + int dx[4] = { 1,0,-1,0 }; + int dy[4] = { 0,1,0,-1 }; + + int N, M; + cin >> N >> M; + char A[10][10]{}; + int px, py, qx, qy; + + + for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) { + cin >> A[i][j]; + if (A[i][j] == 'R') px = i, py = j, A[i][j] = '.'; + if (A[i][j] == 'B') qx = i, qy = j, A[i][j] = '.'; + } + + int vis[10][10][10][10]{}; + vis[px][py][qx][qy]++; + queue> Q; + Q.emplace(px, py, qx, qy, 0); + while (!Q.empty()) { + auto[ax, ay, bx, by, t] = Q.front(); + Q.pop(); + if (A[ax][ay] == 'O') return cout << t, 0; + + for (int i = 0; i < 4; i++) { + int fx = ax, fy = ay, gx, gy; + while (!(fx == bx && fy == by) && A[fx][fy] == '.') fx += dx[i], fy += dy[i]; + if (fx == bx && fy == by) { + gx = bx, gy = by; + while (A[gx][gy] == '.') gx += dx[i], gy += dy[i]; + if (A[gx][gy] == 'O') continue; + gx -= dx[i], gy -= dy[i]; + fx = gx - dx[i], fy = gy - dy[i]; + } + else { + if (A[fx][fy] == '#') fx -= dx[i], fy -= dy[i]; + gx = bx, gy = by; + while (!(gx == fx && gy == fy) && A[gx][gy] == '.') gx += dx[i], gy += dy[i]; + if (A[gx][gy] == 'O') continue; + gx -= dx[i], gy -= dy[i]; + } + if (vis[fx][fy][gx][gy]) continue; + vis[fx][fy][gx][gy]++; + Q.emplace(fx, fy, gx, gy, t + 1); + } + } + cout << -1; + +} +``` From f84b4a2214dbdcf428fb2194872888f771078655 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 8 May 2025 12:28:43 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[BOJ-13905]=20=EC=84=B8=EB=B6=80.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[BOJ-13905] \354\204\270\353\266\200.md" | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13905] \354\204\270\353\266\200.md" diff --git "a/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13905] \354\204\270\353\266\200.md" "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13905] \354\204\270\353\266\200.md" new file mode 100644 index 00000000..24128a7a --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13905] \354\204\270\353\266\200.md" @@ -0,0 +1,103 @@ +# JAVA +```java +import java.util.*; +import java.io.*; + +public class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static int N, M, S, E; + static int[] r; + static int[][] edges; + + static int f(int x) {return x==r[x] ? x : (r[x]=f(r[x]));} + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + N = nextInt(); + M = nextInt(); + S = nextInt(); + E = nextInt(); + r = new int[N+1]; + for(int i=1;i<=N;i++) r[i] = i; + edges = new int[M][]; + for(int i=0;i b[2]-a[2]); + for(int[] e:edges) { + int a = e[0], b = e[1], c = e[2]; + int x = f(a), y = f(b); + if(x == y) continue; + r[x] = y; + if(f(S) == f(E)) { + bw.write(c + "\n"); + return; + } + } + bw.write("0"); + + } + +} +``` + +# CPP +```cpp +#include +#include +#include +#include +using namespace std; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + int N, M, S, E, r[100001]{}; + cin >> N >> M >> S >> E; + + iota(r, r + N + 1, 0); + function f = [&](int x) -> int {return x == r[x] ? x : r[x] = f(r[x]); }; + + priority_queue> Q; + for (int a, b, c; M--; Q.emplace(c, a, b)) cin >> a >> b >> c; + + while (!Q.empty()) { + auto[c, a, b] = Q.top(); Q.pop(); + int x = f(a), y = f(b); + if (x == y) continue; + r[x] = y; + if (f(S) == f(E)) return cout << c, 0; + } + cout << 0; + +} +``` From 6ba2a7c8e0a2375bbd3b14be6c3d19559508fce1 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 8 May 2025 12:29:09 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[BOJ-1727]=20=EC=BB=A4=ED=94=8C=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\247\214\353\223\244\352\270\260.md" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-1727] \354\273\244\355\224\214 \353\247\214\353\223\244\352\270\260.md" diff --git "a/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-1727] \354\273\244\355\224\214 \353\247\214\353\223\244\352\270\260.md" "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-1727] \354\273\244\355\224\214 \353\247\214\353\223\244\352\270\260.md" new file mode 100644 index 00000000..7cadfe40 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-1727] \354\273\244\355\224\214 \353\247\214\353\223\244\352\270\260.md" @@ -0,0 +1,43 @@ +# CPP +```cpp +#include +#include +using namespace std; + +int N, M, A[1001]{}, B[1001]{}; +int dp[1001]{}, mn[1001]{}; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + cin >> N >> M; + for (int i = 1; i <= N; i++) cin >> A[i]; + for (int i = 1; i <= M; i++) cin >> B[i]; + sort(A + 1, A + N + 1); + sort(B + 1, B + M + 1); + + if (N > M) { + swap(N, M); + swap(A, B); + } + + int ans = 2e9; + for (int j = 1; j <= M; j++) { + dp[j] = abs(A[1] - B[j]); + mn[j] = j == 1 ? dp[j] : min(mn[j - 1], dp[j]); + if (N == 1) ans = min(ans, dp[j]); + } + + for (int i = 2; i <= N; i++) { + int ndp[1001]{}, nmn[1001]{}; + for (int j = i; j <= M; j++) { + ndp[j] = mn[j - 1] + abs(A[i] - B[j]); + nmn[j] = j == i ? ndp[j] : min(nmn[j - 1], ndp[j]); + if (i == N) ans = min(ans, ndp[j]); + } + for (int j = 1; j <= M; j++) dp[j] = ndp[j], mn[j] = nmn[j]; + } + cout << ans; + +} +``` From 13a1a489ad38ca0355540e74f0b64469de9b9a09 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 8 May 2025 12:29:33 +0900 Subject: [PATCH 5/5] [BOJ-13141] Ignition.md --- .../[BOJ-13141] Ignition.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13141] Ignition.md" diff --git "a/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13141] Ignition.md" "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13141] Ignition.md" new file mode 100644 index 00000000..f868b719 --- /dev/null +++ "b/\352\266\214\355\230\201\354\244\200_16\354\243\274\354\260\250/[BOJ-13141] Ignition.md" @@ -0,0 +1,38 @@ +# CPP +```cpp +#include +#include +#include +using namespace std; + +int main() { + cin.tie(0)->sync_with_stdio(0); + + int N, M, D[201][201]{}, INF = 1e9 + 7; + cin >> N >> M; + tuple E[20000]{}; + for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) if(i != j) D[i][j] = INF; + for (int i = 0, a, b, c; i < M; i++) { + cin >> a >> b >> c; + D[b][a] = D[a][b] = min(D[a][b], c); + E[i] = { a,b,c }; + } + + for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) for (int k = 1; k <= N; k++) { + int res = D[j][i] + D[i][k]; + D[j][k] = min(D[j][k], D[j][i] + D[i][k]); + } + + int ans = INF; + for (int i = 1; i <= N; i++) { + int res = 0; + for (int j = 0; j < M; j++) { + auto[s, e, l] = E[j]; + res = max(res, D[i][s] + l + D[i][e]); + } + ans = min(ans, res); + } + cout << ans / 2 << "." << ((ans & 1) ? "5" : "0"); + +} +```