結果

問題 No.576 E869120 and Rings
ユーザー 0w10w1
提出日時 2017-11-20 12:25:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,024 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 206,964 KB
実行使用メモリ 23,756 KB
最終ジャッジ日時 2024-05-04 15:07:31
合計ジャッジ時間 27,389 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,196 ms
21,976 KB
testcase_01 AC 1,454 ms
22,220 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 1,081 ms
21,968 KB
testcase_05 AC 1,108 ms
21,968 KB
testcase_06 AC 1,389 ms
22,088 KB
testcase_07 TLE -
testcase_08 AC 890 ms
21,336 KB
testcase_09 AC 676 ms
21,592 KB
testcase_10 AC 808 ms
21,468 KB
testcase_11 AC 781 ms
21,728 KB
testcase_12 AC 767 ms
21,580 KB
testcase_13 AC 714 ms
20,940 KB
testcase_14 AC 802 ms
23,756 KB
testcase_15 AC 351 ms
19,656 KB
testcase_16 AC 444 ms
19,660 KB
testcase_17 AC 795 ms
23,504 KB
testcase_18 AC 819 ms
21,328 KB
testcase_19 AC 836 ms
21,584 KB
testcase_20 AC 662 ms
21,708 KB
testcase_21 AC 843 ms
21,468 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int MAXN = int(5e5);

int N, K;
string A;

double B[MAXN << 1];
double C[MAXN * 2 + 1];

bool ok(double avg) {
  for (int i = 0; i < N; ++i) {
    B[N + i] = B[i] = A[i] - '0' - avg;
  }
  for (int i = 0; i < N << 1; ++i) {
    C[i + 1] = C[i] + B[i];
  }
  deque<pair<double, int>> dq;
  for (int i = K; i < N; ++i) {
    while (!dq.empty() && dq.back().first <= C[i]) dq.pop_back();
    dq.emplace_back(C[i], i);
  }
  for (int i = 0; i < N; ++i) {
    while (!dq.empty() && dq.front().second - i < K) dq.pop_front();
    while (!dq.empty() && dq.back().first <= C[i + N]) dq.pop_back();
    dq.emplace_back(C[i + N], i + N);
    if (dq.front().first - C[i] >= 0.0) return true;
  }
  return false;
}

signed main() {
  ios::sync_with_stdio(false);
  cin >> N >> K;
  cin >> A;
  double lb = 0.0, ub = 1.0;
  for (int i = 0; i < 100; ++i) {
    double mb = (lb + ub) / 2;
    (ok(mb) ? lb : ub) = mb;
  }
  cout << fixed << setprecision(9) << lb << endl;
  return 0;
}
0