結果

問題 No.576 E869120 and Rings
ユーザー vjudge1
提出日時 2025-04-20 22:39:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,176 bytes
コンパイル時間 3,547 ms
コンパイル使用メモリ 283,104 KB
実行使用メモリ 14,320 KB
最終ジャッジ日時 2025-04-20 22:40:28
合計ジャッジ時間 39,571 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
//#define USE_FREOPEN
//#define MUL_TEST
#define FILENAME "sapphire"
using namespace std;
constexpr double eps = 1e-6;
int n,k;
string s;

bool chk(double x) {
	vector<double> sa(2 * n + 1,0.0);
	for (int i = 0; i < 2 * n; i++) {
		sa[i + 1] = sa[i] + (s[i] == '1' ? 1.0 : 0.0) - x;
	}
	deque<int> q;
	for (int i = 1; i <= 2 * n; i++) {
		if (i >= k) {
			while (q.size() && sa[q.back()] >= sa[i - k]) q.pop_back();
			q.push_back(i - k);
		}
		while (q.size() && q.front() < max(i - n,0ll)) q.pop_front();
		if (i >= k) {
			if (q.size()) {
				if (sa[i] - sa[q.front()] >= -1e-9) return 1;
			}
		}
	}
	return 0;
}

void solve() {
	cin >> n >> k >> s;
	s = s + s;
	double l = 0.0,r = 1.0;
	for (int i = 1; i <= 100; i++) {
		double mid = (l + r) / 2.0;
		if (chk(mid)) l = mid;
		else r = mid;
	}
	cout << setprecision(15) << r << '\n';
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

	#ifdef USE_FREOPEN
		freopen(FILENAME ".in","r",stdin);
		freopen(FILENAME ".out","w",stdout);
	#endif
	int _ = 1;
	#ifdef MUL_TEST
		cin >> _;
	#endif
	while (_--)
		solve();
	_^=_;
	return 0^_^0;
}

0