QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661786#8037. Gambler's RuinMENDAXWA 1ms6096kbC++201.1kb2024-10-20 18:06:542024-10-20 18:06:57

Judging History

你现在查看的是最新测评结果

  • [2024-10-20 18:06:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6096kb
  • [2024-10-20 18:06:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
	int x=0,k=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')k=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*k;
}
const int N=1e6+5;
const long double eps=1e-13;
long double p[N];
int n;
struct node{
	long double p;
	int c;
}a[N];
bool cmp(node x,node y){
	return x.p>y.p;
}
void sol(){
	n=read();
	for(int i=1;i<=n;++i)cin>>a[i].p>>a[i].c;
	sort(a+1,a+1+n,cmp);
	int sx=0;
	long double ans=0;
	int r=n;
	int sy=0;
	long double y=1;
	for(int i=1;i<=n;++i){
		while(i>r){
			sy-=a[r+1].c;
			y=1/(1-a[r+1].p);
			++r;
		}
		sx+=a[i].c;
		//if(a[i].p==a[i+1].p)continue;
		long double x=1/a[i].p;
		while(r>i){
			int ssy=sy+a[r].c;
			long double yy=1/(1-a[r].p);
			if(ssy-max(sx*x,ssy*yy)>sy-max(sx*x,sy*y))sy=ssy,y=yy,--r;
			else break;
		}
		while(r>i&&a[r].p==a[r+1].p)sy+=a[r].c,--r;
		ans=max(ans,sx+sy-max(sx*x,sy*y));
	}
	printf("%.10Lf\n",ans);
}
signed main(){
	int T=1;
	while(T--)sol(); 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 6084kb

input:

2
1 15
0 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6040kb

input:

3
0.4 100
0.5 100
0.6 100

output:

33.3333333333

result:

ok found '33.3333333', expected '33.3333333', error '0.0000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 6044kb

input:

1
0 1

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 6096kb

input:

2
1 0
1 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5912kb

input:

1
0.5 100

output:

0.0000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5920kb

input:

3
0.4 100
0.6 100
0.6 100

output:

33.3333333333

result:

wrong answer 1st numbers differ - expected: '0.0000000', found: '33.3333333', error = '33.3333333'