結果

問題 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,148 ms
コンパイル使用メモリ 204,404 KB
実行使用メモリ 23,488 KB
最終ジャッジ日時 2023-08-17 08:17:48
合計ジャッジ時間 25,492 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,134 ms
21,860 KB
testcase_01 AC 1,426 ms
22,128 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 1,093 ms
22,044 KB
testcase_05 AC 1,118 ms
22,184 KB
testcase_06 AC 1,417 ms
21,904 KB
testcase_07 TLE -
testcase_08 AC 879 ms
21,068 KB
testcase_09 AC 693 ms
21,396 KB
testcase_10 AC 798 ms
21,464 KB
testcase_11 AC 776 ms
21,640 KB
testcase_12 AC 719 ms
21,428 KB
testcase_13 AC 659 ms
20,820 KB
testcase_14 AC 810 ms
23,472 KB
testcase_15 AC 301 ms
19,232 KB
testcase_16 AC 396 ms
19,232 KB
testcase_17 AC 727 ms
23,488 KB
testcase_18 AC 776 ms
21,464 KB
testcase_19 AC 789 ms
21,512 KB
testcase_20 AC 621 ms
21,372 KB
testcase_21 AC 780 ms
21,396 KB
testcase_22 AC 2 ms
5,608 KB
testcase_23 AC 2 ms
5,588 KB
testcase_24 AC 2 ms
5,716 KB
testcase_25 AC 2 ms
5,712 KB
testcase_26 AC 2 ms
5,588 KB
testcase_27 AC 2 ms
5,780 KB
testcase_28 AC 2 ms
5,728 KB
testcase_29 AC 2 ms
5,748 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