QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728213 | #5983. Pretty Good Proportion | little_pinkpig | 27 ✓ | 2355ms | 37600kb | C++14 | 1.6kb | 2024-11-09 14:47:13 | 2024-11-09 14:47:14 |
Judging History
answer
#include<bits/stdc++.h>
#define MAXN (500005)
#define ll long long
#define db double
#define pi pair<int,int>
#define fi first
#define se second
using namespace std;
const int lim=500000;
const db eps=1e-8;
template<typename type>
void read(type &x)
{
bool f=0;char ch=0;x=0;
while(ch<'0'||ch>'9'){f|=!(ch^'-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
x=f?-x:x;
}
template<typename type,typename... Args>
void read(type &x,Args &... args)
{
read(x);
read(args...);
}
char str[MAXN];
int test,n,l,r,now,cas;
int s[MAXN];
db p;
struct node{
db a;int b;
inline bool operator<(const node &rsh)const{return a<rsh.a;}
};
set<node> st;
inline void upd_ans(int nl,int nr)
{
if(l==-1) l=nl,r=nr;
else if(fabs((s[r]-s[l-1])*1.0/(r-l+1)-p)>fabs((s[nr]-s[nl-1])*1.0/(nr-nl+1)-p)||(fabs(fabs((s[r]-s[l-1])*1.0/(r-l+1)-p)-fabs((s[nr]-s[nl-1])*1.0/(nr-nl+1)-p))<eps&&nl<l)) l=nl,r=nr;
}
void solve()
{
read(n);scanf("%lf",&p);
scanf("%s",str+1);
for(int i=1;i<=n;i++) s[i]=s[i-1]+(str[i]=='1');
st.clear();l=-1,now=0;
for(int i=1;i<=n;i++)
{
st.insert({now+p*(1-i),i});
if(str[i]=='1') ++now;
auto it=st.lower_bound({now-p*i,0});
if(it!=st.end()) upd_ans((*it).b,i);
if(it!=st.begin()) --it,upd_ans((*it).b,i);
}
printf("Case #%d: %d\n",++cas,l-1);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
read(test);
for(int i=1;i<=test;i++) solve();
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 4ms
memory: 3964kb
input:
100 10 0.827672 0010101011 4 0.932623 0100 1000 0.834002 011001110010111110000110101100010010100101101110110111100010101101111100110001011000110100010100011011000001100001010110111101111010110110000110011000111000011110101100100111111001111011011100111001011101010100111011100011110011100011110010001...
output:
Case #1: 6 Case #2: 1 Case #3: 10 Case #4: 0 Case #5: 0 Case #6: 1 Case #7: 0 Case #8: 0 Case #9: 0 Case #10: 0 Case #11: 0 Case #12: 4 Case #13: 5 Case #14: 564 Case #15: 0 Case #16: 0 Case #17: 0 Case #18: 0 Case #19: 0 Case #20: 0 Case #21: 0 Case #22: 0 Case #23: 0 Case #24: 844 Case #25: 0 Case...
result:
ok 100 lines
Subtask #2:
score: 22
Accepted
Test #2:
score: 22
Accepted
time: 2355ms
memory: 37600kb
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: 6 Case #2: 0 Case #3: 0 Case #4: 2 Case #5: 0 Case #6: 0 Case #7: 0 Case #8: 0 Case #9: 0 Case #10: 0 Case #11: 0 Case #12: 0 Case #13: 0 Case #14: 0 Case #15: 0 Case #16: 4333 Case #17: 0 Case #18: 0 Case #19: 123 Case #20: 0 Case #21: 0 Case #22: 0 Case #23: 0 Case #24: 0 Case #25: 0 Case...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed