QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188840 | #4886. Best Sun | Dualqwq | TL | 958ms | 4176kb | C++23 | 5.7kb | 2023-09-26 15:03:20 | 2023-09-26 15:03:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 5;
typedef long long i64;
typedef double db;
typedef pair<int,int> pii;
#define FI first
#define SE second
const db eps = 1e-9,PI = acos(-1.0);
mt19937 Rnd(114514);
struct Vec {
int x,y;
Vec(){}
Vec(const int _x,const int _y):x(_x),y(_y){}
Vec operator + (const Vec &rhs) const { return Vec(x + rhs.x,y + rhs.y);}
Vec operator - (const Vec &rhs) const { return Vec(x - rhs.x,y - rhs.y);}
i64 operator * (const Vec &rhs) const { return 1ll * x * rhs.y - 1ll * y * rhs.x;}
};
Vec O(0,0);
bool Cmp(const Vec &x,const Vec &y) { return (x.y == y.y) ? (x.x < y.x) : (x.y < y.y);}
i64 Dot(const Vec &A,const Vec &B) { return 1ll * A.x * B.x + 1ll * A.y * B.y;}
db Distance(const Vec &A,const Vec &B) { return sqrt(Dot(A - B,A - B));}
db Angle(const Vec &A) {
db tmp = atan2(A.y,A.x);
// if(tmp < -eps) return tmp + PI * 2;
// else
return tmp;
}
db Area(const Vec &A,const Vec &B,const Vec &C) { return 0.5 * fabs(A * B + B * C + C * A);}
bool Equal(const db &A,const db &B) { return fabs(A - B) < eps;}
db Angle(const Vec &A,const Vec &B,const Vec &C) { // jiao ABC
return Angle(A - B) - Angle(C - B);
}
bool InSegment(const Vec &A,const Vec &B,const Vec &p) { return Equal(Distance(A,p) + Distance(p,B),Distance(A,B));}
bool InTriangle(const Vec &A,const Vec &B,const Vec &C,const Vec &p) {
return Equal(Area(A,B,p) + Area(B,C,p) + Area(C,A,p),Area(A,B,C));
}
Vec Rotate(const Vec &A) { return Vec(-A.y,A.x);}
int sgn(const Vec &A) { return A.y > 0 || A.y == 0 && A.x > 0;}
Vec p[N];
int n;
int V[N][N],VL[N][N];
db sum[N][N];
inline bool CheckTriangle(int i,int j,int k) {
for(int t = 1;t <= n;t++)
if(i != t && j != t && k != t && InTriangle(p[i],p[j],p[k],p[t])) return 0;
return 1;
// if(InSegment(p[i],p[j],p[k])) return VL[i][j] <= 1;
// if(InSegment(p[i],p[k],p[j])) return VL[i][k] <= 1;
// if(InSegment(p[j],p[k],p[i])) return VL[j][k] <= 1;
// if(VL[i][j] || VL[j][k] || VL[i][k]) return false;
// if(i == k || j == k || j == i) return true;
// // if(i == 1 && j == 1 && k == 4) puts("done");
// int num = 0;
// int v1 = V[i][j] - InTriangle(O,p[i],p[j],p[k]);
// int v2 = V[j][k] - InTriangle(O,p[j],p[k],p[i]);
// int v3 = V[k][i] - InTriangle(O,p[k],p[i],p[j]);
// if(p[i] * p[j] > 0) num += v1; else num -= v1;
// if(p[j] * p[k] > 0) num += v2; else num -= v2;
// if(p[k] * p[i] > 0) num += v3; else num -= v3;
// return num == 0;
}
struct Line {
int s,t,type;
Vec v;
Line(){}
Line(const int _s,const int _t,const int _type,const Vec _v):
s(_s),t(_t),type(_type),v(_v){}
bool operator < (const Line &rhs) const {
// return Angle(v) < Angle(rhs.v);
int t1 = sgn(this->v),t2 = sgn(rhs.v);
if(t1 != t2) return t1 > t2;
i64 val = this->v * rhs.v;
// db val = Angle(this->v) - Angle(rhs.v);
if(val) return val > 0;
else return type < rhs.type;
}
};
Line L[N * N];
int tot;
inline void Init() {
cin >> n;
for(int i = 1;i <= n;i++) cin >> p[i].x >> p[i].y;
sort(p + 1,p + n + 1,Cmp);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++)
for(int k = 1;k <= n;k++) {
if(k == i || k == j) continue;
if(!InTriangle(p[i],O,p[j],p[k])) continue;
// if(InSegment(p[i],p[j],p[k]) || (!InSegment(O,p[i],p[k]) && !InSegment(O,p[j],p[k])))
++V[i][j];
if(InSegment(p[i],p[j],p[k])) ++VL[i][j];
}
// printf("V,VL[1,2]:%d,%d\n",V[1][2],VL[1][2]);
// printf("V,VL[3,1]:%d,%d\n",V[3][1],VL[3][1]);
// printf("V,VL[2,3]:%d,%d\n",V[2][3],VL[2][3]);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++)
for(int k = 1;k <= n;k++) {
if(k == i || k == j) continue;
if((p[k] - p[i]) * (p[j] - p[i]) <= 0) continue;
if(Dot(p[j] - p[i],p[k] - p[i]) >= 0 && Dot(p[i] - p[j],p[k] - p[j]) > 0)
sum[i][j] += min(Distance(p[k],p[i]),Distance(p[k],p[j]));
}
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++) {
if(i == j) continue;
sum[i][j] += Distance(p[i],p[j]);
L[++tot] = Line(i,j,0,p[j] - p[i]);
L[++tot] = Line(i,j,1,Rotate(p[j] - p[i]));
}
// printf("Angle(1,2):%.6lf\n",Angle(p[2] - p[1]));
// printf("Angle(1,3):%.6lf\n",Angle(p[3] - p[1]));
// printf("Angle(2,1):%.6lf\n",Angle(p[1] - p[2]));
// printf("Angle(2,3):%.6lf\n",Angle(p[3] - p[2]));
// printf("Angle(3,1):%.6lf\n",Angle(p[1] - p[3]));
// printf("Angle(3,2):%.6lf\n",Angle(p[2] - p[3]));
sort(L + 1,L + tot + 1);
}
db dp[N];
inline bool Check(int st,db mid) {
for(int i = 1;i <= n;i++) dp[i] = -1e15;
dp[st] = -eps;
// printf("Check:%d\n",st);
for(int i = 1;i <= tot;i++) {
int s = L[i].s,t = L[i].t,tp = L[i].type;
// printf("L:%d,%d,%d\n",s,t,tp);
// printf("CheckTriangle[%d,%d,%d]:%d\n",st,s,t,CheckTriangle(st,s,t));
if(tp == 1) {
if(s >= st) dp[s] -= mid * Distance(p[s],p[t]);
} else
if(s >= st && t >= st && CheckTriangle(st,s,t))
dp[t] = max(dp[t],dp[s] + Area(p[st],p[s],p[t]) - mid * sum[s][t]);
}
// for(int i = 1;i <= n;i++) printf("dp[%d]=%.12lf\n",i,dp[i]);
return dp[st] > eps;
}
inline void Clr(int n) {
for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) V[i][j] = VL[i][j] = sum[i][j] = 0;
tot = 0;
}
inline void work() {
Clr(n);
Init();
static int perm[N];
for(int i = 1;i <= n;i++) perm[i] = i;
shuffle(perm + 1,perm + n + 1,Rnd);
db ans = 0;
// printf("Check:%d\n",Check(1,0));
for(int i = 1;i <= n;i++)
if(Check(perm[i],ans)) {
db lef = ans,rig = 1e13;
for(int _ = 1;_ <= 80;_++) {
db mid = (lef + rig) / 2;
if(Check(perm[i],mid)) lef = mid;
else rig = mid;
}
ans = lef;
}
printf("%.10lf\n",ans);
}
int main() {
int T;
cin >> T;
while(T--) work();
return 0;
}
/*
1
4
-832186 456270
289934 43656
636006 339718
188963 113907
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3764kb
input:
4 3 -1 -1 1 -1 0 1 4 0 0 10 0 0 10 8 1 5 2 0 -2 0 1 1 -1 1 0 3 8 4 4 -4 4 4 -4 -4 -4 5 6 -6 5 -5 -6 6 -5
output:
0.3090169941 1.2368614276 0.2711375413 1.5631002094
result:
ok 4 numbers
Test #2:
score: 0
Accepted
time: 94ms
memory: 3792kb
input:
10000 3 702262 828158 -350821 -420883 -466450 13507 3 28647 -193498 126436 -864937 -287798 738936 3 270358 -269567 745815 -485408 834083 677952 3 -2036 -403634 742978 -263774 975937 -609237 3 584248 -472620 482016 -356760 284902 903881 3 -292004 504925 -935756 373793 -781101 -434659 3 -858513 684433...
output:
85789.0873983536 18268.5193616721 102489.9883902622 66685.7544280802 18674.6579374143 106468.9651319721 14427.0246510711 29966.2453025429 143547.7510835874 13097.1756881261 162410.1683169808 72070.9324178747 29369.9926278869 52867.2944311017 90314.3083467567 99775.9271965681 144449.7053083692 64406....
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 105ms
memory: 3724kb
input:
10000 3 2 2 2 -2 -5 -5 3 -3 5 5 -4 2 -2 3 -4 1 2 -2 -4 4 3 1 -4 2 1 -4 1 3 2 1 -1 1 -3 3 3 4 5 3 -1 -3 -3 3 1 5 5 0 5 -1 3 2 -3 -5 -3 5 3 3 -4 4 0 -5 5 4 3 2 -3 5 0 2 -5 3 -2 -3 5 -3 5 4 3 -1 4 4 4 4 3 3 5 3 -1 4 2 -1 3 2 -3 4 3 -4 3 3 0 4 -2 -2 -1 -3 3 -2 0 -4 -2 4 2 3 -3 -1 3 1 1 -3 3 2 -5 2 3 -4 ...
output:
0.6507007010 0.2268090702 0.4946825661 0.8255326311 0.2675324745 0.7379284563 0.1368529466 0.8277457955 1.3896281203 0.2484761663 1.0251262658 0.2252451214 0.7981688503 1.0521776337 0.2700907566 0.2210280034 0.6549291473 1.0657925458 0.1207361881 0.1727212123 0.4458825284 0.2484761663 0.1224985769 0...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 139ms
memory: 3724kb
input:
5625 4 -405394 -381883 602267 -335687 -620806 984110 271283 531233 4 196903 -993060 290851 358123 -890076 -717709 -681138 209884 4 -849589 607722 -21517 -586295 208561 -220953 924518 622983 4 -832186 456270 289934 43656 636006 339718 188963 113907 4 -305762 -872205 -520125 368722 -774548 984204 4245...
output:
232625.0042744304 268175.8269859639 159589.3236305173 60440.7530425985 133893.1234363519 63201.9907486268 167697.6634061348 129470.0132843163 126903.8540728102 106643.9712630971 131692.3112279047 100421.0550162125 148490.2748179024 68842.2423098231 241376.1911161292 303904.5464356643 77462.333614780...
result:
ok 5625 numbers
Test #5:
score: 0
Accepted
time: 137ms
memory: 3804kb
input:
5625 4 -2 -1 4 -5 -2 -4 -4 -4 4 -1 -5 4 4 2 -5 -5 1 4 -3 -4 -3 -1 -5 -1 4 -2 4 -2 4 -4 1 -1 -1 5 -4 4 -3 -5 -1 4 5 -1 3 5 4 -4 -2 1 4 -1 1 3 4 4 -5 3 -3 3 5 -4 -1 4 4 1 2 2 -5 1 0 0 -3 4 -5 -4 2 -3 5 3 -3 2 4 2 -2 -4 3 1 -4 -5 -5 4 -3 5 -2 4 1 3 1 -4 4 0 -5 5 -5 0 -2 -3 2 4 0 5 -1 -4 -2 0 4 -1 4 4 -...
output:
0.4919682067 1.6080239362 0.6764635634 0.8146821264 1.5727954032 0.2020448015 0.4423673057 0.3055832122 1.5089069099 1.3227875237 0.5218559491 0.3982804502 1.2194946257 1.1774912552 1.3951026929 1.0737731259 0.7540897904 0.6075591083 1.4373192211 0.9671123463 0.9534878419 1.4836242816 1.2273730216 0...
result:
ok 5625 numbers
Test #6:
score: 0
Accepted
time: 182ms
memory: 3732kb
input:
3600 5 114127 146710 467065 -311758 189643 449065 -303893 -215009 -789281 -140748 5 -449893 654165 -899120 -560520 719351 652759 285007 471281 987628 -767128 5 -587522 89736 -355416 -178001 801765 512722 314119 -136906 350051 762194 5 85697 920768 161507 -533920 -536515 401333 -27632 -987465 112237 ...
output:
84655.1995486421 270848.7268670469 202824.0367340456 135615.1918739477 119666.5085435062 89811.8707707035 254983.1535753013 189662.7472665110 64951.6570894394 154748.4422910138 214519.6820790362 163467.5328002493 278857.2574408590 191490.4979058230 172625.5296426247 144947.5248148151 232735.62583868...
result:
ok 3600 numbers
Test #7:
score: 0
Accepted
time: 187ms
memory: 3812kb
input:
3600 5 2 6 -6 4 4 0 -5 0 3 1 5 0 3 5 -5 2 6 4 0 2 -4 5 2 -2 -6 -3 -5 -5 -1 3 -4 0 5 0 6 -3 -5 5 1 4 -3 -5 6 5 0 -6 -6 -5 -2 6 1 6 2 0 5 2 1 6 5 4 -1 -3 -2 -6 4 5 -1 -2 5 -6 -1 4 -2 3 6 4 5 -6 3 6 -5 4 -4 3 -1 2 -6 5 5 -4 1 -5 1 0 5 -1 3 2 5 -4 6 2 -4 1 -4 5 5 -1 6 5 -3 0 0 6 -2 5 -5 5 2 6 5 2 -1 -4 ...
output:
1.3917338143 1.0600076760 1.3386604971 2.1786414912 1.8677635295 1.2550644200 1.8197054523 0.9463023191 1.1316433104 1.5772390859 0.5212124231 1.5371795680 0.9473384745 1.0470909880 0.5572297929 1.2085970202 1.2302893723 0.6675741684 0.3665060145 0.6943425487 0.5121414331 0.4362963932 0.8610973425 0...
result:
ok 3600 numbers
Test #8:
score: 0
Accepted
time: 172ms
memory: 3736kb
input:
3600 5 -3 1 0 -1 2 -3 4 1 5 0 5 -3 -5 1 -5 -2 -2 3 2 1 5 5 -4 -2 4 5 5 3 2 -4 -4 0 5 0 4 -5 3 1 4 -1 1 4 1 5 5 -3 2 -5 -3 -4 -1 1 5 1 5 -5 5 -2 1 -3 2 2 2 -4 5 5 -2 -3 -1 3 1 1 3 -2 -2 -2 5 2 1 -2 -3 -3 -3 5 0 -5 4 5 2 2 -2 5 5 -1 4 -5 -2 4 5 -4 5 -1 -3 -2 5 5 -1 -4 3 5 -5 -4 -1 -3 0 -1 -5 1 -4 -3 5...
output:
0.5433808523 1.2079312642 1.5754945742 0.8075181491 1.5566796011 0.6824490669 0.9074401193 0.9508389976 0.8537708828 1.3713082248 0.7426408021 0.4014916240 0.7474276286 0.4934691596 0.7112144950 0.6092998557 1.2344361706 0.4338148297 1.4679333314 0.6954624501 0.6914801784 0.8433199954 1.1987088901 1...
result:
ok 3600 numbers
Test #9:
score: 0
Accepted
time: 182ms
memory: 3616kb
input:
3600 5 0 2 3 -7 7 3 -6 -1 6 -6 5 -3 6 -5 6 -10 -2 -4 -8 -9 8 5 -2 2 2 -9 6 -3 2 10 -5 7 5 -7 9 9 -4 -8 -2 4 10 9 -8 5 -8 -5 -10 0 -7 0 0 -7 6 8 5 10 -7 8 -8 3 1 0 -4 -7 -4 5 2 -9 -3 1 -4 -2 -3 -3 0 1 5 -8 5 -10 6 2 -8 6 -5 -6 8 5 5 8 -8 -9 3 -7 -9 0 -4 3 5 2 -5 2 0 6 7 10 5 -8 -6 5 -10 -2 7 -6 -10 5...
output:
2.1052009171 1.5367686578 1.6070202502 3.5263473234 1.9784334959 1.0825185847 0.9461632266 1.6023271226 2.8837721550 0.9408148761 1.7013625633 1.6009202462 1.9334872525 0.6918659637 1.8339842994 0.6306479689 3.4339518738 2.4487067558 1.5516660625 1.1454890294 0.8735166896 1.5938651480 1.4443102953 2...
result:
ok 3600 numbers
Test #10:
score: 0
Accepted
time: 461ms
memory: 3756kb
input:
900 10 -10 -1 8 -6 7 -1 -5 8 -7 -9 4 -2 -9 10 -10 -8 9 9 -3 -6 10 -5 9 -7 -1 -9 -7 -4 6 -5 2 1 -4 10 8 -9 -9 2 0 7 7 10 -3 -7 9 -4 -5 2 1 1 6 7 -4 7 4 -6 0 1 -8 -5 3 -5 10 -3 -10 -8 -7 -5 -5 -6 3 -3 -1 7 -9 1 -5 9 -7 -2 3 -4 9 10 0 1 -3 8 -3 7 4 -10 10 -6 -5 -8 10 4 4 3 0 -8 3 -10 10 4 -5 2 0 -5 -10...
output:
2.6060274873 1.2633417894 1.1838991150 0.8827284716 1.8782272964 1.5698135836 1.5532953235 1.6328323310 1.5737994846 0.9970959631 0.9424829972 1.4172826337 1.4017665750 1.6939866636 2.8628778514 2.0553597770 2.2087768678 1.3202393918 1.5058644849 1.5958001066 1.9530554956 1.1865717706 1.0563282596 2...
result:
ok 900 numbers
Test #11:
score: 0
Accepted
time: 462ms
memory: 3824kb
input:
900 10 670067 394291 -797310 -637136 -435933 -923795 120936 309795 -934569 -688829 950758 634654 983083 900196 174829 181896 -191047 177910 258020 672165 10 424046 -657491 391198 -14995 -302986 -597011 -96387 -486090 -164032 -356501 -891789 12548 -703186 -924511 808215 -212606 659523 490088 738901 5...
output:
81290.1618383874 91483.7331961633 100154.0270558443 192606.4148203157 177441.6474344190 76150.8923721784 177358.7053738850 230115.8792668132 280209.2628450281 61218.5430212881 137504.7916377359 168344.5440410830 162167.1818149091 133102.5292692334 177087.4563457421 163543.6097759953 184494.309868970...
result:
ok 900 numbers
Test #12:
score: 0
Accepted
time: 958ms
memory: 3844kb
input:
225 20 -4 -9 -5 3 7 -10 10 7 2 7 1 4 2 2 -5 -1 -9 -1 -3 10 -8 -6 0 -5 7 -4 -6 -8 -7 -5 -1 -7 -1 -3 8 -6 6 3 8 2 20 8 2 6 -8 -3 -6 -2 9 5 -2 0 8 8 0 -7 -9 3 1 4 -10 4 7 -6 -1 -8 -7 2 -8 -8 -1 1 -9 2 -10 1 2 -7 8 -10 3 20 5 8 0 -3 9 -9 -10 -4 -10 -2 9 10 -2 8 -6 -10 6 -6 -3 7 5 10 7 7 -5 -6 -2 3 -4 0 ...
output:
0.6127869879 1.1137907228 0.7615364367 1.3308059089 0.7540492246 1.3328379773 0.6703147980 1.0353128055 0.9068174085 0.9769666622 0.7502848963 0.7780315779 0.7179049212 0.5715802295 0.7721061101 0.7692910320 1.8904459998 0.8600960664 1.0777332394 1.3129810864 0.8016468379 0.8696199196 0.8573236626 1...
result:
ok 225 numbers
Test #13:
score: 0
Accepted
time: 953ms
memory: 3716kb
input:
225 20 983700 -466859 -20884 -364855 807044 -308568 -785298 910840 -61173 -276993 -872226 -878552 -235162 831941 978289 938037 585612 -598517 545857 403231 -450887 -558997 -293044 -675226 -900628 102932 -836719 -530135 -534412 -681687 -487340 -227869 161252 -557533 397943 464720 170537 68556 413322 ...
output:
103902.0526005497 185063.0384573682 60443.6573723298 118360.3646096527 157018.7851307661 103511.4658062487 65549.6994793018 67043.3588288789 105010.2705326798 93450.0576684484 96005.2282076065 54350.0986013047 134718.5353431403 98397.3545701083 71213.2949663770 77465.3939447632 75212.0930408158 1236...
result:
ok 225 numbers
Test #14:
score: 0
Accepted
time: 349ms
memory: 4176kb
input:
6 50 -107573 -479674 -523931 117259 705403 519626 -802569 -162243 510741 876735 206326 -333274 448335 -276206 482965 -837837 873180 -965235 -359525 608790 -53827 782310 689038 -718590 739597 111296 420387 -953079 -492679 -243600 -929509 1174 800731 -968797 208236 193620 249265 499134 848153 771472 5...
output:
20480.3828540030 21190.0221497545 27821.6725958813 28113.3193405331 27223.9676079334 31857.8357100238
result:
ok 6 numbers
Test #15:
score: -100
Time Limit Exceeded
input:
36 50 569818 -279771 972561 928848 383 744221 -453534 -154445 293032 502859 744851 436690 293077 503053 657 744258 317135 -276665 293067 502799 277103 -439313 282010 -387735 276848 -439025 972274 928763 -110443 -507380 744799 436605 282061 -387926 -453689 -154326 317468 -276534 -453630 -154510 28193...
output:
81019.4274544065 77527.2587729804 55029.2464233124 42253.1543856523 72715.8578229929 197374.6307406517 37469.7225819230 66130.3529953654 54454.5978065124 125611.0883685242 71800.2062730508 87529.3367688078 143932.8876147904 95010.1346815147 86801.3479385008 106229.4888661122 99367.3086457770 93764.6...