QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#264066 | #7734. Intersection over Union | ucup-team2230# | AC ✓ | 66ms | 3776kb | C++17 | 8.9kb | 2023-11-25 12:16:36 | 2023-11-25 12:16:37 |
Judging History
answer
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
//#include <unordered_map>
//#include <unordered_set>
#include <cassert>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>
#include <complex>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <atcoder/convolution>
//#include <atcoder/lazysegtree>
//#include <atcoder/maxflow>
//#include <atcoder/mincostflow>
//#include <atcoder/segtree>
//#include <atcoder/string>
using namespace std;
//using namespace atcoder;
#define int long long
//#define L __int128
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define gnr(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define per(i,b) gnr(i,0,b)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) (int)(x.size())
#define pcnt(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.fi<<","<<p.sc<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
//https://codeforces.com/blog/entry/62393
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
//don't make x negative!
size_t operator()(pair<int,int> x)const{
return operator()(uint64_t(x.first)<<32|x.second);
}
};
//unordered_set -> dtype, null_type
//unordered_map -> dtype(key), dtype(value)
using namespace __gnu_pbds;
template<class t,class u>
using hash_table=gp_hash_table<t,u,custom_hash>;
template<class T>
void o(const T &a,bool space=false){
cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;
//const ll mod = 1000000007;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
struct mint{
ll v;
mint(ll vv=0){s(vv%mod+mod);}
mint& s(ll vv){
v=vv<mod?vv:vv-mod;
return *this;
}
mint operator-()const{return mint()-*this;}
mint &operator+=(const mint&rhs){return s(v+rhs.v);}
mint &operator-=(const mint&rhs){return s(v+mod-rhs.v);}
mint &operator*=(const mint&rhs){v=ll(v)*rhs.v%mod;return *this;}
mint &operator/=(const mint&rhs){return *this*=rhs.inv();}
mint operator+(const mint&rhs)const{return mint(*this)+=rhs;}
mint operator-(const mint&rhs)const{return mint(*this)-=rhs;}
mint operator*(const mint&rhs)const{return mint(*this)*=rhs;}
mint operator/(const mint&rhs)const{return mint(*this)/=rhs;}
mint pow(ll n)const{
if(n<0)return inv().pow(-n);
mint res(1),x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
mint inv()const{return pow(mod-2);}
friend mint operator+(ll x,const mint&y){
return mint(x)+y;
}
friend mint operator-(ll x,const mint&y){
return mint(x)-y;
}
friend mint operator*(ll x,const mint&y){
return mint(x)*y;
}
friend mint operator/(ll x,const mint&y){
return mint(x)/y;
}
friend ostream& operator<<(ostream&os,const mint&m){
return os<<m.v;
}
friend istream& operator>>(istream&is,mint&m){
ll x;is>>x;
m=mint(x);
return is;
}
bool operator<(const mint&r)const{return v<r.v;}
bool operator==(const mint&r)const{return v==r.v;}
bool operator!=(const mint&r)const{return v!=r.v;}
explicit operator bool()const{
return v;
}
};
ll modpow(ll x,ll n,ll _md=mod){
ll res=1;
while(n>0){
if(n&1) res=res*x%_md;
x=x*x%_md;
n>>=1;
}
return res;
}
#define _sz 1
mint F[_sz],R[_sz];
void make(){
F[0] = 1;
for(int i=1;i<_sz;i++) F[i] = F[i-1] * i;
R[_sz-1] = F[_sz-1].pow(mod-2);
for(int i=_sz-2;i>=0;i--) R[i] = R[i+1] * (i+1);
}
mint C(int a,int b){
if(b < 0 || a < b) return mint();
return F[a]*R[b]*R[a-b];
}
using ld=long double;
using vi=vc<int>;
using ull=unsigned long long;
/*int dst(P p, P q){
return (p.a-q.a)*(p.a-q.a)+(p.b-q.b)*(p.b-q.b);
}*/
/*template<class t>
void add_inplace(t &a, t b){
if(a.size() < b.size()) swap(a, b);
for(int i=0;i<si(b);i++){
a[i] += b[i];
if(a[i] < 0) a[i] += mod;
if(a[i] >= mod) a[i] -= mod;
}
return ;
}*/
template<class t>
void ov(const vc<t>&a){
if(a.empty()) return;
rep(i, si(a)) cout << a[i] << (i+1==si(a)?'\n':' ');
}
//o(ans?"Yes":"No");
#define ld long double
#define x real()
#define y imag()
using pt=complex<ld>;
using d=array<ld,6>;
d add(d a,d b){
rep(i,6) a[i]+=b[i];
return a;
}
bool ok(ld a,ld b,ld c,ld lb=0,ld ub=1){
if(a*lb*lb+b*lb+c >= 0) return 1;
if(a*ub*ub+b*ub+c >= 0) return 1;
ld xx = -b/a/2;
if(lb<=xx and xx<=ub and a*xx*xx+b*xx+c >= 0) return 1;
return 0;
}
void solve(){
pt pp[4],p[4];
ld xmn=1e18,ymn=1e18,xmx=-1e18,ymx=-1e18;
rep(i,4){
ld ap,q;
cin>>ap>>q;
pp[i]=pt(ap,q);
chmin(xmn,ap); chmax(xmx,ap);
chmin(ymn,q); chmax(ymx,q);
}
if(pp[0].x == pp[1].x or pp[0].y == pp[1].y){
o(1);
return;
}
rep(i,4){
if(pp[i].x==xmn)p[0] = pp[i];
if(pp[i].y==ymn)p[1] = pp[i];
if(pp[i].x==xmx)p[2] = pp[i];
if(pp[i].y==ymx)p[3] = pp[i];
}
d up=d{};
up[5] = abs(p[0]-p[1])*abs(p[1]-p[2]);
ld coef1 = 0;
coef1 += (p[0].y-p[1].y)/(p[1].x-p[0].x);
coef1 += (p[3].y-p[0].y)/(p[3].x-p[0].x);
ld coef2 = 0;
coef2 += (p[1].x-p[0].x)/(p[0].y-p[1].y);
coef2 += (p[2].x-p[1].x)/(p[2].y-p[1].y);
ld r = xmx-xmn;
ld c = ymx-ymn;
up = add(up,d{-r*r/4*coef1,-c*c/4*coef2,0,0,0,0});
d dw=d{r*r/4*coef1,c*c/4*coef2,r*c,-r*c,-r*c,r*c};
/*for(ld ax=0;ax<=1;ax+=0.0001){
for(ld ay=0;ay<=1;ay+=0.0001){
ld U = up[0]*ax*ax+up[1]*ay*ay+up[2]*ax*ay+up[3]*ax+up[4]*ay+up[5];
ld D = dw[0]*ax*ax+dw[1]*ay*ay+dw[2]*ax*ay+dw[3]*ax+dw[4]*ay+dw[5];
chmax(ans, U/D);
}
}*/
ld lb = 0,ub = 1;
rep(i,64){
ld mid=(lb+ub)/2;
d cur = up;
rep(i,6) cur[i]-=dw[i]*mid;
bool f = 0;
if(ok(cur[1],cur[4],cur[5]))f=1;
if(ok(cur[1],cur[2]+cur[4],cur[0]+cur[3]+cur[5]))f=1;
if(ok(cur[0],cur[3],cur[5]))f=1;
if(ok(cur[0],cur[2]+cur[3],cur[1]+cur[4]+cur[5]))f=1;
ld a=-cur[2]/cur[1]/2;
ld b=-cur[4]/cur[1]/2;
{
ld lb=-b/a, ub=(1.0L-b)/a;
if(lb>ub)swap(lb,ub);
chmax(lb,0.0L); chmin(ub,1.0L);
if(lb <= ub){
ld tw = cur[0]+cur[1]*a*a+cur[2]*a;
ld on = cur[3]+cur[4]*a+cur[2]*b+cur[1]*a*b*2;
ld ze = cur[1]*b*b+cur[4]*b+cur[5];
if(ok(tw,on,ze,lb,ub))f=1;
}
}
if(f)lb=mid;
else ub=mid;
}
ld ans = lb;
// cerr<<ans<<endl;
if(p[1].x > p[3].x){
rep(i,4) p[i] = pt(p[i].x, -p[i].y);
swap(p[1],p[3]);
}
ld dx = p[3].x-p[0].x;
ld dy = p[3].y-p[0].y;
ld s = dx*dy/sqrt(dx*dx+dy*dy);
ld t = abs(p[0]-p[1]);
if(s <= t/2){
chmax(ans, dx*dy/abs(p[0]-p[1])/abs(p[1]-p[2]));
}
else{
chmax(ans, t*t*dx*dy/abs(p[0]-p[1])/abs(p[1]-p[2])/s/s/4);
lb = 0,ub = 1;
rep(i,64){
ld mid=(lb+ub)/2;
//t/s/2<=k<=1
// ld co = (k-t/s/2);
//co*co*dx*dy+abs(p[0]-p[1])*abs(p[1]-p[2]);
//k*k*dx*dy-co*co*dx*dy;
//t/s*dx*dy k - t*t/s/s/4*dx*dy
//dx*dy k^2 -t/s*dx*dy k t*t/s/s/4*dx*dy
array<ld,3>up={0, t/s*dx*dy, -t*t/s/s/4*dx*dy};
array<ld,3>dw={dx*dy ,-t/s*dx*dy, t*t/s/s/4*dx*dy+abs(p[0]-p[1])*abs(p[1]-p[2])};
bool f= 0;
if(ok(up[0]-dw[0]*mid, up[1]-dw[1]*mid, up[2]-dw[2]*mid, t/s/2, 1))f=1;
if(f)lb=mid;
else ub=mid;
}
//cerr<<lb<<endl;
chmax(ans, lb);
}
o(ans);
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int t; cin >> t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
3 0 2 2 0 0 -2 -2 0 7 -2 9 -2 9 2 7 2 7 13 11 10 5 2 1 5
output:
0.70710678118654752433 1 0.62384322483109367024
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 59ms
memory: 3668kb
input:
10000 -568767734 379152673 -565681345 -54946093 -131582579 -51859704 -134668968 382239062 -194884120 -559906233 -194884142 -158042604 -998611400 -158042648 -998611378 -559906277 459335966 -945199065 478030260 -934243779 450535683 -887326546 431841389 -898281832 -483567491 491964356 -523827401 408140...
output:
0.99296541252647004927 0.99999993156883114028 0.59086981567862606007 0.62177048491080393262 0.57883238413512740360 1 0.49999999737417563514 0.68523458057386939951 0.45596171976721498672 0.50028739390208505617 0.98029611059210510101 0.49204357179154079065 0.54403738870671087923 0.38048010710523953569...
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
11 -999999999 238255972 -999999998 238255969 1000000000 904922635 999999999 904922638 678595699 247253438 -168427985 235963055 -168327599 228431927 678696085 239722310 -192017652 -554548342 868151340 -554547158 868151544 -737211410 -192017448 -737212594 -999841167 -113051212 -112620642 -999956242 99...
output:
0.00003535596408252989 0.50022088590642687180 0.99999666287698491050 0.69630788885775816212 0.00003162327663726040 0.28251770996713316533 0.99122103253953508457 0.16452921001040721243 0.05818740240908304017 0.13825759387592938948 0.04744473217643556227
result:
ok 11 numbers
Test #4:
score: 0
Accepted
time: 58ms
memory: 3776kb
input:
10000 -948990367 928227410 -873396995 996000778 851933079 -928405843 776339707 -996179211 -109521044 -738814438 897130737 -601388427 761521924 391952296 -245129857 254526285 534464734 -606222047 863618110 -14372639 -542024234 767366629 -871177610 175517221 636708790 -567653754 157968528 -562763908 1...
output:
0.15078853544727063407 0.88803120075968691407 0.61262235796682009060 0.98242536604426466073 0.66847652347018970249 0.99997801536379838142 0.46532406104744505681 1 0.95911969795504607093 0.75733536202649657946 0.69724693218880541334 0.29259150548288863483 0.03846304652408570471 0.91821270985748746512...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 66ms
memory: 3660kb
input:
10000 0 1 1 0 4 3 3 4 0 1 3 0 8 15 5 16 0 5 25 0 64 195 39 200 0 7 49 0 124 525 75 532 0 8 4 0 34 15 30 23 0 8 12 0 38 39 26 47 0 40 100 0 274 435 174 475 0 56 196 0 514 1113 318 1169 0 32 8 0 212 51 204 83 0 32 24 0 124 75 100 107 0 160 200 0 692 615 492 775 0 224 392 0 1172 1365 780 1589 0 1081897...
output:
0.49999999999999999995 0.49999999999999999995 0.50000000000000000000 0.50000000000000000011 0.50000000000000000000 0.50000000000000000000 0.50000000000000000000 0.50000000000000000000 0.49999999999999999995 0.49999999999999999995 0.50000000000000000000 0.50000000000000000000 0.49998061213560057774 0...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 52ms
memory: 3660kb
input:
10000 0 1 1 0 2 1 1 2 -1000000000 -999999999 -999999999 -1000000000 1000000000 999999999 999999999 1000000000 -1000000000 -999999999 999999999 -1000000000 1000000000 999999999 -999999999 1000000000 -1000000000 0 0 -1000000000 1000000000 0 0 1000000000 0 1 1 0 1000000000 999999999 999999999 100000000...
output:
0.70710678118654752433 0.00001581151330528886 0.99999999950000000015 0.70710678118654752444 0.00002236092978757600 0.99999999900000000058 0.99912269159020067783 0.09850178135278598560 0.08441949174412753426 0.99217257629802579975 0.71050532478837425879 0.99999997554761989473 0.00077722908368440131 0...
result:
ok 10000 numbers
Test #7:
score: 0
Accepted
time: 56ms
memory: 3688kb
input:
10000 0 508076 762114 0 762124 15 10 508091 -998442427 -981568404 -498442427 -981568405 -498442425 18431595 -998442425 18431596 0 1 250000000 0 250000001 250000000 1 250000001 -999999999 -27628659 -999999998 -27628661 1000000000 972371338 999999999 972371340 -999999999 238255972 -999999998 238255969...
output:
0.00327047422434106791 0.99999999750000000706 0.99999999600000002395 0.00002500031251445340 0.00003535596408252989 0.00004609878484480894 0.00006800966511699995 0.00010124740883692585 0.00014578442315928050 0.00021274310096928100 0.00031329816943577937 0.00046981768420957851 0.00070469831716131167 0...
result:
ok 10000 numbers
Extra Test:
score: 0
Extra Test Passed