結果

問題 No.576 E869120 and Rings
ユーザー e869120e869120
提出日時 2017-10-11 21:14:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 74,648 KB
実行使用メモリ 43,628 KB
最終ジャッジ日時 2024-04-28 16:17:37
合計ジャッジ時間 22,363 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 752 ms
40,664 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
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];

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);
	for (int i = 0; i < n; i++) { if (W[i + m] >= d[i])return true; }
	return false;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		char e; cin >> e;
		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