比赛 20241126 评测结果 AAAAAAAAAA
题目名称 小b爱实数 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 1.658 s
代码语言 C++ 内存使用 39.78 MiB
提交时间 2024-11-26 10:53:29
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<double,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e6+10;
const double eps = 1e-9;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}

int n;
double pre[N],x;
set<pii>s;
char c[N];

int main(){
	freopen("changgao_real.in","r",stdin);
	freopen("changgao_real.out","w",stdout);
	scanf("%lf%s",&x,c + 1);
	n = strlen(c + 1);
	for(int i = 1;i <= n;i++)pre[i] = pre[i-1] + (c[i] == '1');
	s.insert({0,0});
	pii ans = {100,-1};
	for(int i = 1;i <= n;i++){
		double now = pre[i] - x * i;
		auto it = s.lower_bound({now,i});
		if(it != s.end()){
			if(fabs((double)(pre[i] - pre[(*it).se]) / (i - (*it).se) - x) + eps < ans.fi)
				ans = {fabs((double)(pre[i] - pre[(*it).se]) / (i - (*it).se) - x),(*it).se};
		}
		if(it != s.begin()){
			it--;
			if(fabs((double)(pre[i] - pre[(*it).se]) / (i - (*it).se) - x) + eps < ans.fi)
				ans = {fabs((double)(pre[i] - pre[(*it).se]) / (i - (*it).se) - x),(*it).se};
		}
		s.insert({now,i});
	}
	printf("%d\n",ans.se);

	return 0;

}