結果
問題 |
No.576 E869120 and Rings
|
ユーザー |
![]() |
提出日時 | 2025-04-22 19:02:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 345 ms / 1,500 ms |
コード長 | 1,146 bytes |
コンパイル時間 | 1,722 ms |
コンパイル使用メモリ | 166,992 KB |
実行使用メモリ | 20,688 KB |
最終ジャッジ日時 | 2025-04-22 19:02:39 |
合計ジャッジ時間 | 8,039 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define endl '\n' typedef double f64; const int N = 1e6 + 10; const f64 eps = 1e-7; int n, k; string s; f64 a[N], sum[N]; inline bool check(f64 x) { for (int i = 1; i <= n; i++) a[i] = a[i + n] = (s[i] - '0' - x); for (int i = 1; i <= 2 * n; i++) sum[i] = sum[i - 1] + a[i]; deque<int> q; q.push_back(0); for (int i = k; i <= 2 * n; i++) { while (!q.empty() && i - q.front() > n) q.pop_front(); int j = q.front(); if (sum[i] - sum[j] > eps) return 1; while (!q.empty() && sum[q.back()] - sum[i - k + 1] > eps) q.pop_back(); q.push_back(i - k + 1); } return 0; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> k >> s; s = ' ' + s; f64 l = 0, r = 1, ans = l; while (r - l > eps) { f64 mid = (l + r) / 2; if (check(mid)) ans = mid, l = mid; else r = mid; } cout << fixed << setprecision(15) << ans << endl; return 0; }