QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#753803 | #5983. Pretty Good Proportion | mzmz001 | 0 | 5374ms | 20816kb | C++14 | 1.3kb | 2024-11-16 13:39:42 | 2024-11-16 13:39:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct H{long double w;long long x,y;}a[1000007];
bool cmp(H x,H y){return x.w<y.w;}
long long n,m,k,l,s,wl,fl,ts;
long double f;
const long double eps=1e-9,weps=1e-12;
string st;
bool ch(long double d){
long double ma=-1e9,mi=1e9;wl=1e9;++ts;
for(int i=0;i<=n;i++){
ma=max(ma,a[i].y+a[i].x*-(f+d));
if(fabs(ma-(a[i].y+a[i].x*-(f+d)))>weps)wl=min(wl,a[i].x+1);
}
for(int i=n;i>=0;i--){
mi=min(mi,a[i].y+a[i].x*-(f+d));
if(fabs(mi-(a[i].y+a[i].x*-(f+d)))>weps)wl=min(wl,a[i].x+1);
}
ma=-1e9;mi=1e9;
for(int i=0;i<=n;i++){
ma=max(ma,a[i].y+a[i].x*-(f-d));
if(fabs(ma-(a[i].y+a[i].x*-(f-d)))>weps)wl=min(wl,a[i].x+1);
}
for(int i=n;i>=0;i--){
mi=min(mi,a[i].y+a[i].x*-(f-d));
if(fabs(mi-(a[i].y+a[i].x*-(f-d)))>weps)wl=min(wl,a[i].x+1);
}
return (wl!=1e9);
}
int main(){
// freopen("c.in","r",stdin);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T,sd;
cin>>T;
while(T--){
cin>>sd;fl=1;
cin>>f>>st;n=st.size();a[0].w=a[0].x=a[0].y=0;
for(int i=1;i<=n;i++)a[i].w=-f+(st[i-1]-'0')+a[i-1].w,a[i].x=i,a[i].y=a[i-1].y+st[i-1]-'0';
sort(a,a+n+1,cmp);
long double l=0,r=1;
while((r-l)>eps){
long double mid=(l+r)/2;
if(ch(mid))r=mid,fl=wl;
else l=mid;
}
cout<<fl-1<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 14ms
memory: 3892kb
input:
100 10 0.827672 0010101011 4 0.932623 0100 1000 0.834002 011001110010111110000110101100010010100101101110110111100010101101111100110001011000110100010100011011000001100001010110111101111010110110000110011000111000011110101100100111111001111011011100111001011101010100111011100011110011100011110010001...
output:
6 1 10 0 0 1 0 0 0 0 0 4 5 564 0 0 0 0 0 0 0 0 0 844 0 0 1 155 0 0 0 0 0 0 393 1 173 0 2 0 130 3 0 840 1 5 0 0 74 0 1 0 0 0 0 0 1 0 1 0 0 0 8 0 0 838 2 2 0 0 0 612 0 5 0 0 0 0 0 0 1 0 320 0 0 6 79 0 0 0 0 0 1 0 1 158 0 0 3 0
result:
wrong answer 1st lines differ - expected: 'Case #1: 6', found: '6'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 5374ms
memory: 20816kb
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:
6 0 0 2 0 0 0 0 0 0 0 0 0 0 0 4333 0 0 123 0 0 0 0 0 0 0 0 3 0 676 0 0 2 0 0 0 0 0 1 2 0 278 2 1 1 0 0 0 0 0 0 0 0 1 0 1 0 5 5 0 1 1 0 2 1 0 6 3 0 500 1 0 0 1 0 1 188 3 0 6 499838 0 0 5 0 0 0 499840 0 0 8 4 0 1 0 0 0 92 0 0
result:
wrong answer 1st lines differ - expected: 'Case #1: 6', found: '6'