QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386331 | #5809. Min Perimeter | L_Hospital_ | 5 | 17641ms | 222808kb | C++14 | 2.9kb | 2024-04-11 15:35:22 | 2024-04-11 15:35:22 |
Judging History
answer
#include<bits/stdc++.h>
# define int long long
# define rep(i, j, k) for (int i = j; i <= k; ++i)
# define dis(i, j) sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]))
using namespace std;
int n, x[1000005], y[1000005], dx[1000005], dy[1000005], st[1000005];
int qex[10] = {0, 1, 1, 1, -4, 3, 5, 7}, qey[10] = {1, 0, 1, -2, 9, 4, -3, 2};
bool b = true;
long double d[105][105], anx[1000005];
double ddl[1000005][21];
void solvebf()
{
long double ans = 10000000000000000LL;
rep(i, 1, n) rep(j, i + 1, n) d[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
rep(i, 1, n) rep(j, i + 1, n) rep(k, j + 1, n) ans = min(ans, d[i][j] + d[i][k] + d[j][k]);
cout << fixed << setprecision(15) << ans << '\n';
}
bool cmp(int a, int b){return x[a] < x[b];}
void solveeasy()
{
rep(i, 1, n) st[i] = i;
sort(st + 1, st + n + 1, cmp);
int ans = 100000000000LL;
rep(i, 1, n - 2) ans = min(ans, 2 * (x[st[i + 2]] - x[st[i]]));
cout << ans << '\n';
}
bool cmp1(int a, int b){return anx[a] < anx[b];}
void solvediff()
{
double ans = 1000000000000000LL;
rep(i, 1, n) x[i] += 1000000001, y[i] += 1000000001;
rep(i, 1, n) dx[i] = 5 * x[i] - 2 * y[i] + 10000000001LL, dy[i] = 2 * x[i] + 5 * y[i] + 10000000001LL, anx[i] = (long double) (1.0) * dx[i] * dy[i], st[i] = i;
sort(st + 1, st + n + 1, cmp1);
rep(i, 1, n) rep(k, 1, 20) if (i + k <= n) ddl[i][k] = dis(st[i], st[i + k]);
rep(i, 1, n) rep(j, i + 1, min(i + 20, n)) rep(k, j + 1, min(i + 20, n)) ans = min(ans, ddl[i][j - i] + ddl[i][k - i] + ddl[j][k - j]);
rep(i, 1, n) dx[i] = 1 * x[i] + 3 * y[i] + 10000000001LL, dy[i] = 3 * x[i] - 1 * y[i] + 10000000001LL, anx[i] = (long double) (1.0) * dx[i] * dy[i];
sort(st + 1, st + n + 1, cmp);
rep(i, 1, n) rep(k, 1, 20) if (i + k <= n) ddl[i][k] = dis(st[i], st[i + k]);
rep(i, 1, n) rep(j, i + 1, min(i + 20, n)) rep(k, j + 1, min(i + 20, n)) ans = min(ans, ddl[i][j - i] + ddl[i][k - i] + ddl[j][k - j]);
rep(i, 1, n) dx[i] = 3 * x[i] + 1 * y[i] + 10000000001LL, dy[i] = 1 * x[i] - 3 * y[i] + 10000000001LL, anx[i] = (long double) (1.0) * dx[i] * dy[i];
sort(st + 1, st + n + 1, cmp1);
rep(i, 1, n) rep(k, 1, 20) if (i + k <= n) ddl[i][k] = dis(st[i], st[i + k]);
rep(i, 1, n) rep(j, i + 1, min(i + 20, n)) rep(k, j + 1, min(i + 20, n)) ans = min(ans, ddl[i][j - i] + ddl[i][k - i] + ddl[j][k - j]);
cout << fixed << setprecision(15) << ans << '\n';
}
signed main()
{
// freopen("triangle.in", "r", stdin);
// freopen("triangle.out", "w", stdout);
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int T; cin >> T; rep(tt, 1, T)
{
cout << "Case #" << tt << ": ";
cin >> n;
rep(i, 1, n) cin >> x[i] >> y[i], b &= (!y[i]);
if (n <= 100) solvebf();
else if (b) solveeasy();
else solvediff();
}
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 133ms
memory: 19988kb
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.893012206204873 Case #2: 1042.844834964388099 Case #3: 1711142102.791327029466629 Case #4: 90912.296374032928725 Case #5: 3.414213562373095 Case #6: 26.153830342163694 Case #7: 1701.012681095616927 Case #8: 2865438.191993871238083 Case #9: 2020088.337226319592446 Case #10: 1792106.037292...
result:
ok correct! (15 test cases)
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 17641ms
memory: 222808kb
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.133089721202850 Case #2: 3414213562.373095035552979 Case #3: 866.071590574358879 Case #4: 62459.895369637146359 Case #5: 91545.029078863619361 Case #6: 898200.352464858209714 Case #7: 1707101.209072277182713 Case #8: 1703.583090325173544 Case #9: 1702.080487705073665 Case #10: 680...
result:
wrong answer read 91545.029078863619 but expected 59141.918358931784 (test case 5)