結果

問題 No.576 E869120 and Rings
ユーザー e869120e869120
提出日時 2017-10-11 21:37:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,243 ms / 1,500 ms
コード長 1,373 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 73,680 KB
実行使用メモリ 41,280 KB
最終ジャッジ日時 2024-04-28 16:15:51
合計ジャッジ時間 24,078 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,170 ms
40,384 KB
testcase_01 AC 1,072 ms
40,128 KB
testcase_02 AC 1,093 ms
40,384 KB
testcase_03 AC 1,109 ms
40,380 KB
testcase_04 AC 993 ms
40,388 KB
testcase_05 AC 1,243 ms
40,384 KB
testcase_06 AC 988 ms
40,252 KB
testcase_07 AC 1,079 ms
40,256 KB
testcase_08 AC 977 ms
40,384 KB
testcase_09 AC 768 ms
40,252 KB
testcase_10 AC 801 ms
40,380 KB
testcase_11 AC 796 ms
40,384 KB
testcase_12 AC 770 ms
40,512 KB
testcase_13 AC 819 ms
41,276 KB
testcase_14 AC 753 ms
41,280 KB
testcase_15 AC 755 ms
41,280 KB
testcase_16 AC 825 ms
41,280 KB
testcase_17 AC 792 ms
41,280 KB
testcase_18 AC 802 ms
40,476 KB
testcase_19 AC 965 ms
40,384 KB
testcase_20 AC 832 ms
40,256 KB
testcase_21 AC 798 ms
40,384 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 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 + 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