QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#753688#5983. Pretty Good Proportionhzlqwq0 1ms9912kbC++171.4kb2024-11-16 13:27:162024-11-16 13:27:28

Judging History

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

  • [2024-11-16 13:27:28]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:9912kb
  • [2024-11-16 13:27:16]
  • 提交

answer

#pragma GCC optimize(3)
#include <iostream>
#include <cstring>
#define int long long
#define v first
#define p second

using namespace std;

const int N=1e6+5,inf=1e7;

int n,f,cnt[N];
pair<int,int> a[N],b[N]; 
char s[N];

void dfs(int l,int r){
	if (l==r) return;
	int mid=l+r>>1,i=l,j=mid+1,k=l;
	dfs(l,mid),dfs(mid+1,r);
	while (i<=mid&&j<=r)
		if (a[i].v<=a[j].v) cnt[a[i].p]+=r-j+1,b[k++]=a[i++];
		else b[k++]=a[j++];
	while (i<=mid) b[k++]=a[i++];
	while (j<=r) b[k++]=a[j++];
	for (int i=l;i<=r;i++) a[i]=b[i];
}

void sfd(int l,int r){
	if (l==r) return;
	int mid=l+r>>1,i=l,j=mid+1,k=l;
	sfd(l,mid),sfd(mid+1,r);
	while (i<=mid&&j<=r)
		if (a[i].v<a[j].v) cnt[a[i].p]+=j-mid-1,b[k++]=a[i++];
		else b[k++]=a[j++];
	while (i<=mid) cnt[a[i].p]+=r-mid,b[k++]=a[i++];
	while (j<=r) b[k++]=a[j++];
	for (int i=l;i<=r;i++) a[i]=b[i];
}

bool check(int m){
	cnt[0]=0,a[0]={0,0};
	for (int i=1;i<=n;i++)
		cnt[i]=0,a[i]={a[i-1].v+(s[i]-'0')*inf-f+m,i};
	dfs(0,n),a[0]={0,0};
	for (int i=1;i<=n;i++)
		a[i]={a[i-1].v+(s[i]-'0')*inf-f-m,i};
	sfd(0,n);
	for (int i=0;i<=n;i++)
		if (cnt[i]>n-i) return 1;
	return 0;
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	double t;
	cin>>t,f=t*inf;
	cin>>s+1;
	n=strlen(s+1);
	int l=-1,r=inf;
	while (l+1^r){
		int mid=l+r>>1;
		(check(mid)?r:l)=mid;
	}
	check(r);
	for (int i=0;i<=n;i++)
		if (cnt[i]>n-i){
			cout<<i<<"\n";
			return 0;
		}
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7812kb

input:

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

output:


result:

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

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 9912kb

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:

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