QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#385838 | #5809. Min Perimeter | wsyear | 20 ✓ | 8423ms | 11832kb | C++14 | 2.0kb | 2024-04-11 08:47:07 | 2024-04-11 08:47:08 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 1000010;
int n;
pii a[maxn];
double ans = 1e10;
double dis(pii x, pii y) {
return sqrt(1ll * (x.fi - y.fi) * (x.fi - y.fi) + 1ll * (x.se - y.se) * (x.se - y.se));
}
void solve(int l, int r) {
if (l == r) return;
int mid = (l + r) >> 1;
solve(l, mid), solve(mid + 1, r);
double lim = ans / 2;
vector<pii> pl, pr;
rep (i, l, mid) if (fabs(a[i].fi - a[mid].fi) <= lim) pl.emplace_back(a[i]);
rep (i, mid + 1, r) if (fabs(a[i].fi - a[mid].fi) <= lim) pr.emplace_back(a[i]);
sort(ALL(pl), [&](pii x, pii y) { return x.se < y.se; });
sort(ALL(pr), [&](pii x, pii y) { return x.se < y.se; });
int L = 0, R = -1, sz = SZ(pr);
for (pii x : pl) {
while (L < sz && x.se - pr[L].se > lim) L++;
while (R + 1 < sz && pr[R + 1].se - x.se <= lim) R++;
rep (i, L, R) rep (j, i + 1, R) chkmn(ans, dis(x, pr[i]) + dis(x, pr[j]) + dis(pr[i], pr[j]));
}
L = 0, R = -1, sz = SZ(pl);
for (pii x : pr) {
while (L < sz && x.se - pl[L].se > lim) L++;
while (R + 1 < sz && pl[R + 1].se - x.se <= lim) R++;
rep (i, L, R) rep (j, i + 1, R) chkmn(ans, dis(x, pl[i]) + dis(x, pl[j]) + dis(pl[i], pl[j]));
}
}
void work() {
cin >> n, ans = 1e10;
rep (i, 1, n) cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1), solve(1, n);
cout << fixed << setprecision(10) << ans << '\n';
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
int t; cin >> t;
rep (i, 1, t) cout << "Case #" << i << ": ", work();
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 45ms
memory: 3940kb
input:
15 3 2 6 7 0 3 0 3 713 269 371 79 455 421 3 91983245 637281504 756917015 312173515 869576338 436726680 10000 14761642 78236002 9047458 47951098 5238002 27761162 476182 2523742 1428546 7571226 26190010 138805810 21904372 116092132 18094916 95902196 43332562 229660522 55237112 292754072 52380020 27761...
output:
Case #1: 17.8930122062 Case #2: 1042.8448349644 Case #3: 1711142102.7913269997 Case #4: 90912.2963740329 Case #5: 3.4142135624 Case #6: 26.1538303422 Case #7: 1701.0126810956 Case #8: 2865438.1919938712 Case #9: 2020088.3372263198 Case #10: 1792106.0372920712 Case #11: 2019352.5429097286 Case #12: 2...
result:
ok correct! (15 test cases)
Subtask #2:
score: 15
Accepted
Test #2:
score: 15
Accepted
time: 8423ms
memory: 11832kb
input:
15 3 501691275 344354353 167768963 536043860 249445040 557426549 4 1000000000 0 0 0 1000000000 1000000000 0 1000000000 1000000 138925776 669369648 61257680 295150640 170762328 822763944 55483472 267329456 97736936 470914328 84041848 404928904 18463588 88960924 124429360 599523280 95066048 458045504 ...
output:
Case #1: 799653579.1330897808 Case #2: 3414213562.3730950356 Case #3: 866.0715905744 Case #4: 62459.8953696371 Case #5: 59141.9183589318 Case #6: 898195.0909682680 Case #7: 1707085.7699867852 Case #8: 1686.2267982581 Case #9: 1686.6035459716 Case #10: 6806.6655839363 Case #11: 1907363.0783250025 Cas...
result:
ok correct! (15 test cases)
Extra Test:
score: 0
Extra Test Passed