結果

問題 No.576 E869120 and Rings
ユーザー square1001square1001
提出日時 2017-10-11 21:56:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 1,500 ms
コード長 797 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 55,248 KB
実行使用メモリ 14,160 KB
最終ジャッジ日時 2023-08-10 23:17:14
合計ジャッジ時間 10,144 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 502 ms
13,212 KB
testcase_01 AC 500 ms
13,252 KB
testcase_02 AC 557 ms
13,256 KB
testcase_03 AC 564 ms
13,216 KB
testcase_04 AC 498 ms
13,288 KB
testcase_05 AC 502 ms
13,236 KB
testcase_06 AC 509 ms
13,280 KB
testcase_07 AC 565 ms
13,160 KB
testcase_08 AC 295 ms
13,172 KB
testcase_09 AC 268 ms
13,216 KB
testcase_10 AC 292 ms
13,168 KB
testcase_11 AC 284 ms
13,228 KB
testcase_12 AC 273 ms
13,164 KB
testcase_13 AC 242 ms
13,160 KB
testcase_14 AC 264 ms
14,160 KB
testcase_15 AC 188 ms
13,176 KB
testcase_16 AC 221 ms
13,216 KB
testcase_17 AC 259 ms
14,052 KB
testcase_18 AC 270 ms
13,212 KB
testcase_19 AC 270 ms
13,224 KB
testcase_20 AC 268 ms
13,292 KB
testcase_21 AC 270 ms
13,264 KB
testcase_22 AC 2 ms
5,084 KB
testcase_23 AC 2 ms
4,984 KB
testcase_24 AC 2 ms
5,068 KB
testcase_25 AC 2 ms
5,040 KB
testcase_26 AC 2 ms
5,108 KB
testcase_27 AC 2 ms
5,024 KB
testcase_28 AC 2 ms
5,032 KB
testcase_29 AC 2 ms
4,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int N, M, deq[1000009]; double vs[1000009]; char s[500009];
bool solve(double x) {
	int ps = 0;
	for (int i = 1; i <= 2 * N; i++) {
		ps += s[(i - 1) % N] - 48;
		vs[i] = ps - x * i;
	}
	int l = 0, r = 0;
	for (int i = M; i < N; i++) {
		while (l < r && vs[deq[r - 1]] < vs[i]) r--;
		deq[r++] = i;
	}
	for (int i = 0; i < N; i++) {
		while (l < r && vs[deq[r - 1]] < vs[i + N]) r--;
		deq[r++] = i + N;
		if (vs[deq[l]] >= vs[i] - 1.0e-12) return true;
		if (deq[l] == i + M) l++;
	}
	return false;
}
int main() {
	scanf("%d %d", &N, &M);
	scanf("%s", s);
	double l = 0.0, r = 1.0;
	for (int i = 0; i < 40; i++) {
		double m = (l + r) * 0.5;
		if (solve(m)) l = m;
		else r = m;
	}
	printf("%.12lf\n", l);
	return 0;
}
0