QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728045#5983. Pretty Good ProportionBigJoker0 2283ms44836kbC++141.1kb2024-11-09 14:26:392024-11-09 14:26:39

Judging History

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

  • [2024-11-09 14:26:39]
  • 评测
  • 测评结果:0
  • 用时:2283ms
  • 内存:44836kb
  • [2024-11-09 14:26:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n;
int a[N],sx[N],sy[N];
double f[N],p;
set<pair<double,int> >S;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int _;
	cin>>_;
	for(int t=1;t<=_;t++){
		cin>>n>>p;
		for(int i=1;i<=n;i++){
			char x;
			cin>>x;
			a[i]=x-'0';
			sx[i]=sx[i-1]+a[i];
			sy[i]=sy[i-1]+1;
		}
		for(int i=0;i<=n;i++)
			f[i]=sx[i]-p*sy[i]; 
		S.clear();
		double ans=1e9;
		int al=n;
		for(int i=n;i;i--){
			S.insert(make_pair(f[i],i));
			auto R=S.upper_bound(make_pair(f[i-1],114514)),L=R;
			if(R!=S.end()){
				int l=i,r=(*R).second;
				double ret=(sx[r]-sx[l-1])/1.0/(sy[r]-sy[l-1]);
				if(fabs(ret-p)<=fabs(ans-p)){
					ans=ret;
					al=l;
				}
			}
			if(R!=S.begin()){
				L--;
				int l=i,r=(*L).second;
				double ret=(sx[r]-sx[l-1])/1.0/(sy[r]-sy[l-1]);
				if(fabs(ret-p)<=fabs(ans-p)){
					ans=ret;
					al=l;
				}
			}
		}
		cout<<"Case #"<<t<<": "<<al<<'\n';
	}
	return 0;
}
/*
1
7 0.5
1101110

4
7 0.5
1101110
11 0.8
11111011110
9 0.75
011001011
9 0.666
010111100
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5912kb

input:

100
10 0.827672
0010101011
4 0.932623
0100
1000 0.834002
011001110010111110000110101100010010100101101110110111100010101101111100110001011000110100010100011011000001100001010110111101111010110110000110011000111000011110101100100111111001111011011100111001011101010100111011100011110011100011110010001...

output:

Case #1: 7
Case #2: 2
Case #3: 11
Case #4: 1
Case #5: 1
Case #6: 2
Case #7: 1
Case #8: 1
Case #9: 1
Case #10: 1
Case #11: 1
Case #12: 5
Case #13: 6
Case #14: 565
Case #15: 1
Case #16: 1
Case #17: 1
Case #18: 1
Case #19: 1
Case #20: 1
Case #21: 1
Case #22: 1
Case #23: 1
Case #24: 845
Case #25: 1
Case...

result:

wrong answer 1st lines differ - expected: 'Case #1: 6', found: 'Case #1: 7'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 2283ms
memory: 44836kb

input:

100
15 0.333333
000000000011000
10 0.418754
0101100001
2 0.499999
01
3 0.977951
001
2 0.249999
01
10 0.670229
0111011001
1000 0.500001
001101111110110010110000010010110001110010001101110111010011000010100011011101010110011011011010111110011100011000001000101011100011010100101101111110100101011010111...

output:

Case #1: 7
Case #2: 1
Case #3: 1
Case #4: 3
Case #5: 1
Case #6: 1
Case #7: 1
Case #8: 1
Case #9: 1
Case #10: 1
Case #11: 1
Case #12: 1
Case #13: 1
Case #14: 1
Case #15: 1
Case #16: 4334
Case #17: 1
Case #18: 1
Case #19: 124
Case #20: 1
Case #21: 1
Case #22: 1
Case #23: 1
Case #24: 1
Case #25: 1
Case...

result:

wrong answer 1st lines differ - expected: 'Case #1: 6', found: 'Case #1: 7'