#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pll pair #define pis pair #define psi pair const int inf = 1000000001; const ll INF = 1e16; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout< a(n); for (i = 0; i < n; i++) { scanf(" %c", &c); if (c == '0') { a[i] = 0; } else { a[i] = 1; } } a.insert(a.end(), a.begin(), a.end()); //DEBUG_VEC(a); double left = 0, right = 1, ans = 0; while (left + 0.00000005 < right) { double x = (left + right) / 2; vector b = a; for (i = 0; i < 2 * n; i++) { b[i] -= x; } //DEBUG_VEC(b); vector sum(2 * n + 1); sum[0] = 0; for (i = 0; i < 2 * n; i++) { sum[i + 1] = sum[i] + b[i]; } //DEBUG_VEC(sum); deque dq; for (i = k; i < n; i++) { while (!dq.empty() && sum[dq[dq.size() - 1]] <= sum[i]) { dq.pop_back(); } dq.push_back(i); } /* for (i = 0; i < dq.size(); i++) { printf("%d ", dq[i]); } printf("\n"); */ bool flag = false; for (i = 0; i < n; i++) { while (!dq.empty() && sum[dq[dq.size() - 1]] <= sum[i + n]) { dq.pop_back(); } dq.push_back(i + n); while (dq[0] < i + k) { dq.pop_front(); } if (sum[dq[0]] >= sum[i]) { flag = true; } if (flag) { break; } } if (flag) { left = x + 0.00000005; ans = x; } else { right = x; } } Sp(ans); }