QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430967#5902. Upstairs/Downstairsfanglong30 ✓7675ms42920kbC++14980b2024-06-04 19:14:052024-06-04 19:14:06

Judging History

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

  • [2024-06-04 19:14:06]
  • 评测
  • 测评结果:30
  • 用时:7675ms
  • 内存:42920kb
  • [2024-06-04 19:14:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x;
}
const int N=1000010;
int n,k,m;
double d[N];
bool cmp(double i,double j){
	return i>j;
}
double pf[N],sf[N],pg[N],sg[N];
int main(){
	int T=read();
	for(int t=1;t<=T;t++){
		n=read(),k=read();
		m=0;
		for(int i=1;i<=n;i++){
			int a=read(),b=read(),c=read();
			double k=1.0*a/b;
			while(c--)d[++m]=k;
		}
		sort(d+1,d+m+1,cmp);
		pf[0]=sf[0]=1;
		for(int i=1;i<=m;i++){
			pf[i]=pf[i-1]*d[i];
			sf[i]=sf[i-1]-(sf[i-1]-pf[i-1])*d[i];
		}
		pg[m+1]=sg[m+1]=1;
		for(int i=m;i>=1;i--){
			pg[i]=pg[i+1]*(1-d[i]);
			sg[i]=sg[i+1]-(sg[i+1]-pg[i+1])*(1-d[i]);
		}
		double ans=0;
		for(int i=k,j=m+1;i>=0;i--,j--)ans=max(ans,sf[i]*pg[j]+pf[i]*sg[j]-pf[i]*pg[j]);
		cout<<fixed<<setprecision(9)<<"Case #"<<t<<": "<<1-ans<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 13
Accepted

Test #1:

score: 13
Accepted
time: 2ms
memory: 12036kb

input:

100
4 1
1/2 3
1/5 2
2/5 1
2/2 2
3 2
1/2 2
1/3 2
3/4 2
3 3
99/100 1
1/2 2
1/50 3
8 7
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
19 17
1/15 1
2/9 8
3/5 4
2/7 4
2/7 9
6/12 3
5/10 3
9/14 5
2/4 4
13/18 9
8/12 4
2/5 6
1/4 10
8/10 2
5/13 3
4/12 8
8/12 10
4/16 3
9/14 4
23 4
2/14 6
7/11 1
3/8 5
2/3 3
3/...

output:

Case #1: 0.000000000
Case #2: 0.083333333
Case #3: 0.015000000
Case #4: 0.937500000
Case #5: 0.972519685
Case #6: 0.280716368
Case #7: 0.653116312
Case #8: 0.625007979
Case #9: 0.714352006
Case #10: 0.899193148
Case #11: 0.340576172
Case #12: 0.746759461
Case #13: 0.000000000
Case #14: 0.000000000
C...

result:

ok correct! (100 test cases)

Subtask #2:

score: 17
Accepted

Test #2:

score: 17
Accepted
time: 7675ms
memory: 42920kb

input:

100
4 1
1/2 3
1/5 2
2/5 1
2/2 2
3 2
1/2 2
1/3 2
3/4 2
3 3
99/100 1
1/2 2
1/50 3
8 7
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
1/2 1
19 17
1/15 1
2/9 8
3/5 4
2/7 4
2/7 9
6/12 3
5/10 3
9/14 5
2/4 4
13/18 9
8/12 4
2/5 6
1/4 10
8/10 2
5/13 3
4/12 8
8/12 10
4/16 3
9/14 4
23 4
2/14 6
7/11 1
3/8 5
2/3 3
3/...

output:

Case #1: 0.000000000
Case #2: 0.083333333
Case #3: 0.015000000
Case #4: 0.937500000
Case #5: 0.972519685
Case #6: 0.280716368
Case #7: 0.653116312
Case #8: 0.625007979
Case #9: 0.714352006
Case #10: 0.899193148
Case #11: 0.981122241
Case #12: 0.584037952
Case #13: 0.765986193
Case #14: 0.496987392
C...

result:

ok correct! (100 test cases)

Extra Test:

score: 0
Extra Test Passed