QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#515873#5983. Pretty Good ProportionFLY0 209ms8088kbC++141.6kb2024-08-12 10:33:252024-08-12 10:33:25

Judging History

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

  • [2024-08-12 10:33:25]
  • 评测
  • 测评结果:0
  • 用时:209ms
  • 内存:8088kb
  • [2024-08-12 10:33:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define gc getchar
#define pb push_back
#define all(x) x.begin(),x.end()
#define y1 __
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define dFor(i,a,b) for(int i=(a);i>=(b);i--)
#define tomin(x,y) x=min(x,y)
#define tomax(x,y) x=max(x,y)
#define abs_(x) max(x,-(x))
#define eq(x,y) (abs_((x)-(y))<=eps)
#define ull unsigned long long
const int N=5e5+5;
const db eps=1e-12;
int read()
{
	int x=0; int y=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') y=0;
	for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
	return y?x:-x;
}
char getc() { char c=getchar(); for(;!isdigit(c)&&!isalpha(c);c=getchar()); return c; }

int n;
db p;
char ch[N];
int a[N],sm[N];
db ans;
int as;
struct _N
{
	int x;
	db y;
	bool operator <(_N t)const
	{
		if(eq(y,t.y)) return x<t.x;
		return y<t.y;
	}
}b[N];
db slope(_N x,_N y)
{
	return ((y.y-x.y)/(y.x-x.x));
}
void upd(int x,db y)
{
	if(y<ans-eps||eq(y,ans)&&x<as) as=x,ans=y;
}
void work2()
{
	For(i,1,n) sm[i]=sm[i-1]+a[i];
	For(i,1,n) b[i]=(_N){i,p*i-sm[i]};
	b[0]=(_N){0,0};
	sort(b,b+n+1);
	For(i,0,n-1) if(b[i].x<b[i+1].x) upd(b[i].x+1,slope(b[i],b[i+1]));
}
int work()
{
	scanf("%d%lf",&n,&p);
	scanf("%s",&ch[1]);
	For(i,1,n) a[i]=ch[i]-'0';
	
	ans=2; as=0;
	
	work2();
	For(i,1,n) a[i]^=1;
	p=1-p;
	work2();
	return as-1;
}
int main()
{
//	freopen("tii.in","r",stdin);
//	freopen("tii.out","w",stdout); 
	int T=read();
	For(i,1,T) printf("Case #%d: %d\n",i,work());
//	while(T--) printf("%d\n",work());
	return 0;
}
/*



*/



详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 209ms
memory: 8088kb

input:

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

output:

Case #1: 0
Case #2: -1
Case #3: -1
Case #4: -1
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: -1
Case #17: -1
Case #18: -1
Case #19: -1
Case #20: -1
Case #21: -1
Case #22: -1
Case #23: -1
Case #24: -...

result:

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

Subtask #2:

score: 0
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

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:


result: