QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329282 | #1880. Nikanor Loves Games | wsc2008 | WA | 1ms | 18256kb | C++14 | 2.0kb | 2024-02-16 15:39:42 | 2024-02-16 15:39:42 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=5e5+9,INF=1e16;
ll n,a[N],b[N],x[N],tot,va[N],vb[N],pre[N*2],q[N],l=1,r,vv[N*2];
struct Node{
ll x,v;
}t[N*2],c[N],d[N];
ld slope(ll i,ll j){
ll xa=c[i].x,ya=c[i].v,xb=c[j].x,yb=c[j].v;
if(xa==xb)return -INF;
return (ya-yb)*1.0/(xb-xa);
}
ll getp(ll x){
ll l=1,r=tot,p=0;
while(l<=r){
ll mid=(l+r)>>1;
if(vv[mid]<=x)p=mid,l=mid+1;
else r=mid-1;
}
return p;
}
int main(){
// freopen("gamble.in","r",stdin);
// freopen("gamble.out","w",stdout);
n=read();
rep(i,1,n)a[i]=read(),b[i]=read(),x[i]=read();
rep(i,1,n)t[++tot]=(Node){a[i],x[i]},t[++tot]=(Node){b[i],x[i]};
sort(t+1,t+tot+1,[&](Node a,Node b){
return a.x<b.x||(a.x==b.x&&a.v<b.v);
});
ll ru=0;
rep(i,1,n)ru+=4*x[i];
rep(i,1,tot)pre[i]=pre[i-1]+t[i].v,vv[i]=t[i].x;
rep(i,1,n){
ll p=getp(a[i]);
va[i]=pre[p]*2;
p=getp(b[i]);
vb[i]=pre[p]*2;
}
//max(va[i]+vb[j]-4a[i]b[j])
a[0]=1;
ll ans=-INF;
c[0]=(Node){-4,0};
rep(i,1,n)c[i]=(Node){-4*b[i],vb[i]};
rep(i,0,n)d[i]=(Node){a[i],va[i]};
sort(c+0,c+n+1,[&](Node a,Node b){
return a.x<b.x;
});
sort(d+0,d+n+1,[&](Node a,Node b){
return a.x<b.x;
});
rep(i,0,n){
while(l+1<=r&&slope(q[r-1],q[r])>=slope(q[r],i))r--;
q[++r]=i;
}
// if(n<=2000){
// rep(i,0,n){
// rep(j,0,n)ans=max(ans,va[i]+c[j].v+c[j].x*a[i]);
// }
// write(ans-ru);
// return 0;
// }
rep(i,0,n){
while(l+1<=r&&slope(q[l],q[l+1])<=d[i].x)l++;
ans=max(ans,d[i].v+c[q[l]].v+c[q[l]].x*d[i].x);
}
cout<<fixed<<setprecision(12)<<(ans-ru)*0.25;
// write(ans-ru);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18128kb
input:
2 1 4 15 3 5 10
output:
2.500000000000
result:
ok found '2.5000000', expected '2.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 18256kb
input:
1 2 2 8
output:
4.000000000000
result:
ok found '4.0000000', expected '4.0000000', error '0.0000000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 18124kb
input:
3 94 68 49 51 2 63 26 85 20
output:
-94.000000000000
result:
wrong answer 1st numbers differ - expected: '-73.0000000', found: '-94.0000000', error = '0.2876712'