From eb7fb2606c4132f55c3105952dba645d501e2901 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 27 Nov 2025 15:01:46 +0900 Subject: [PATCH] =?UTF-8?q?[20251127]=20BOJ=20/=20P3=20/=20=E8=AA=8D?= =?UTF-8?q?=E8=A8=BC=E3=83=AC=E3=83=99=E3=83=AB=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 --- ...74\343\203\254\343\203\231\343\203\253.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "khj20006/202511/27 BOJ P3 \350\252\215\350\250\274\343\203\254\343\203\231\343\203\253.md" diff --git "a/khj20006/202511/27 BOJ P3 \350\252\215\350\250\274\343\203\254\343\203\231\343\203\253.md" "b/khj20006/202511/27 BOJ P3 \350\252\215\350\250\274\343\203\254\343\203\231\343\203\253.md" new file mode 100644 index 00000000..e5756562 --- /dev/null +++ "b/khj20006/202511/27 BOJ P3 \350\252\215\350\250\274\343\203\254\343\203\231\343\203\253.md" @@ -0,0 +1,84 @@ +```cpp +#include +using namespace std; + +const int dx[4] = {1,0,-1,0}; +const int dy[4] = {0,1,0,-1}; + +int R; + +vector> office() { + int N, M, X, Y; + cin>>M>>N>>Y>>X; + Y--, X--; + + int root[250000]{}; + int cnt[250000]{}; + iota(root, root+N*M, 0); + fill(cnt, cnt+N*M, 1); + function find = [&](int x) -> int { return x == root[x] ? x : root[x] = find(root[x]); }; + + bitset<250000> vis; + vis[X*M+Y] = 1; + + vector> infos; + for(int i=0;i>a; + infos.emplace_back(a,i,j); + } + + sort(infos.begin(), infos.end()); + vector> events; + for(int i=0;i(infos[j]) == cc) { + auto [c,a,b] = infos[j]; + vis[a*M+b] = 1; + for(int k=0;k<4;k++) { + int aa = a+dx[k], bb = b+dy[k]; + if(aa<0 || aa>=N || bb<0 || bb>=M || !vis[aa*M+bb]) continue; + int x = find(a*M+b), y = find(aa*M+bb); + if(x == y) continue; + cnt[y] += cnt[x]; + root[x] = y; + } + j++; + } + i = j; + events.emplace_back(cc, cnt[find(X*M+Y)]); + } + + return events; +} + +int main(){ + cin.tie(0)->sync_with_stdio(0); + + cin>>R; + vector> res1 = office(); + vector> res2 = office(); + + int ans = 2e9 + 1; + for(auto [c,v] : res1) if(v >= R) { + ans = min(ans, c); + break; + } + for(auto [c,v] : res2) if(v >= R) { + ans = min(ans, c); + break; + } + for(int i=0,j=res2.size()-1;i= R) { + while(j>=0 && res1[i].second + res2[j].second >= R) j--; + j++; + } + if(res1[i].second + res2[j].second >= R) { + ans = min(ans, res1[i].first + res2[j].first); + } + } + cout<