QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#753377#5983. Pretty Good ProportionFXT1110011010OI0 1ms5964kbC++141.4kb2024-11-16 12:39:042024-11-16 12:39:04

Judging History

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

  • [2024-11-16 12:39:04]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5964kb
  • [2024-11-16 12:39:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef pair<double, int> PDI;
const int N = 1e6 + 10;
const double eps = 1e-9;

char a[N]; 
int sum[N];

int main()
{
	int T; scanf("%d", &T);
	while (T -- )
	{
		int n; double f; scanf("%d%lf%s", &n, &f, a + 1);
		for (int i = 1; i <= n; i ++ ) sum[i] = sum[i - 1] + a[i] - '0';
		if (n <= 1000)
		{
			double mn = 1e9; int res = 1e9;
			for (int i = 1; i <= n; i ++ )
				for (int j = i; j <= n; j ++ )
				{
					double now = 1.0 * (sum[j] - sum[i - 1]) / (j - i + 1);
					if (fabs(mn - f) > fabs(now - f)) mn = now, res = i;
					else if (fabs(fabs(mn - f) - fabs(now - f)) < eps) res = min(res, i);
				}
			printf("%d\n", res - 1);
			return 0;
		}
		double mn = 1e9; int res = 1e9;
		set<PDI> ag;
		for (int i = 1; i <= n; i ++ )
		{
			ag.insert({1.0 * sum[i - 1] - f * (i - 1), i});
			auto it = ag.lower_bound({1.0 * sum[i] - f * i, 0});
			if (it != ag.end())
			{
				double v = (*it).first - (1.0 * sum[i] - f * i);
				if (mn - v > eps) mn = v, res = (*it).second;
				else if (fabs(mn - v) < eps) res = min(res, (*it).second);
			}
			if (it != ag.begin())
			{
				it -- ;
				double v = (1.0 * sum[i] - f * i) - (*it).first;
				if (mn - v > eps) mn = v, res = (*it).second;
				else if (fabs(mn - v) < eps) res = min(res, (*it).second);
			}
		}
		printf("%d\n", res - 1);
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

6

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: 1ms
memory: 5964kb

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

result:

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