結果

問題 No.576 E869120 and Rings
ユーザー square1001square1001
提出日時 2017-10-12 17:10:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 1,500 ms
コード長 797 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 55,784 KB
実行使用メモリ 15,124 KB
最終ジャッジ日時 2024-04-28 17:06:43
合計ジャッジ時間 5,724 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 238 ms
14,936 KB
testcase_01 AC 227 ms
13,824 KB
testcase_02 AC 253 ms
13,472 KB
testcase_03 AC 262 ms
14,748 KB
testcase_04 AC 235 ms
14,928 KB
testcase_05 AC 233 ms
13,720 KB
testcase_06 AC 241 ms
13,184 KB
testcase_07 AC 259 ms
13,612 KB
testcase_08 AC 149 ms
13,416 KB
testcase_09 AC 132 ms
13,340 KB
testcase_10 AC 140 ms
13,512 KB
testcase_11 AC 136 ms
12,764 KB
testcase_12 AC 140 ms
12,800 KB
testcase_13 AC 122 ms
13,012 KB
testcase_14 AC 130 ms
15,124 KB
testcase_15 AC 85 ms
11,620 KB
testcase_16 AC 96 ms
11,728 KB
testcase_17 AC 125 ms
14,188 KB
testcase_18 AC 131 ms
13,200 KB
testcase_19 AC 131 ms
13,748 KB
testcase_20 AC 130 ms
12,728 KB
testcase_21 AC 131 ms
12,740 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,940 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 < 20; i++) {
		double m = (l + r) * 0.5;
		if (solve(m)) l = m;
		else r = m;
	}
	printf("%.12lf\n", l);
	return 0;
}
0