結果

問題 No.576 E869120 and Rings
ユーザー e869120e869120
提出日時 2017-10-11 21:37:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 946 ms / 1,500 ms
コード長 1,369 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 74,176 KB
実行使用メモリ 42,100 KB
最終ジャッジ日時 2023-08-10 23:14:58
合計ジャッジ時間 18,991 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 909 ms
41,844 KB
testcase_01 AC 929 ms
41,000 KB
testcase_02 AC 902 ms
42,020 KB
testcase_03 AC 903 ms
41,104 KB
testcase_04 AC 901 ms
41,748 KB
testcase_05 AC 914 ms
40,216 KB
testcase_06 AC 901 ms
40,704 KB
testcase_07 AC 946 ms
40,520 KB
testcase_08 AC 637 ms
41,572 KB
testcase_09 AC 633 ms
40,720 KB
testcase_10 AC 611 ms
40,912 KB
testcase_11 AC 623 ms
41,040 KB
testcase_12 AC 549 ms
41,572 KB
testcase_13 AC 649 ms
42,100 KB
testcase_14 AC 611 ms
41,684 KB
testcase_15 AC 591 ms
41,692 KB
testcase_16 AC 652 ms
41,692 KB
testcase_17 AC 637 ms
41,976 KB
testcase_18 AC 645 ms
40,992 KB
testcase_19 AC 631 ms
40,940 KB
testcase_20 AC 614 ms
40,680 KB
testcase_21 AC 644 ms
40,764 KB
testcase_22 AC 2 ms
7,696 KB
testcase_23 AC 3 ms
7,868 KB
testcase_24 AC 2 ms
7,712 KB
testcase_25 AC 2 ms
7,580 KB
testcase_26 AC 2 ms
7,576 KB
testcase_27 AC 3 ms
7,580 KB
testcase_28 AC 3 ms
7,708 KB
testcase_29 AC 2 ms
7,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

#pragma warning(disable: 4996)

/*string ID = "01";

FILE *in = freopen(("./in" + ID + ".txt").c_str(), "r", stdin);
FILE *out = freopen(("./out" + ID + ".txt").c_str(), "w", stdout);*/

int n, m; double c[500009], d[500009], deq[1000009]; char S[500050];

vector<double> slide_max(vector<double>&x, int r) {
	vector<double> F; int s = 0, t = 0;
	for (int i = 0; i < x.size(); i++)deq[i] = 0;
	for (int i = 0; i < x.size(); i++) {
		while (s < t && x[deq[t - 1]] <= x[i]) t--;
		deq[t++] = i;
		if (i - r + 1 >= 0) {
			F.emplace_back(x[deq[s]]);
			if (deq[s] == i - r + 1) s++;
		}
	}
	return F;
}

bool solve(double p) {
	for (int i = 0; i < n; i++) d[i] = c[i] - p;
	for (int i = 1; i < n; i++) d[i] += d[i - 1];

	vector<double>V;
	for (int i = 0; i < n * 2; i++) { V.push_back(d[i%n] + d[n - 1] * (i / n)); }
	vector<double>W = slide_max(V, n - m + 1);
	for (int i = 0; i < n; i++) { if (W[i + m] >= d[i])return true; }
	return false;
}

int main() {
	cin >> n >> m;
	scanf("%s", &S);
	for (int i = 0; i < n; i++) {
		char e = S[i];
		if (e == '0')c[i] = 0.0;
		if (e == '1')c[i] = 1.0;
	}

	double L = 0, R = 1, M;
	for (int i = 0; i < 30; i++) {
		M = (L + R) / 2.0;
		bool I = solve(M);
		if (I == true)L = M; else R = M;
	}
	printf("%.12lf\n", M);
	return 0;
}
0