結果

問題 No.576 E869120 and Rings
ユーザー pekempeypekempey
提出日時 2017-10-14 01:31:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 983 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 79,772 KB
実行使用メモリ 39,784 KB
最終ジャッジ日時 2024-04-28 17:58:34
合計ジャッジ時間 6,250 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

// blue[l,r)/(r-l
// blue[l,r)/(r-l) >= x
// blue[l,r] >= x(r-l)
// blue[r]-blue[l] >= xr - xl
// blue[r]-xr >= blue[l] >= xl
// r-l>=K

int main() {
  int n, k;
  std::cin >> n >> k;

  std::string s;
  std::cin >> s;
  s += s;

  std::vector<int> sum(n * 2 + 1);
  for (int i = 0; i < n * 2; i++) {
    sum[i + 1] = sum[i] + (s[i % n] == '1');
  }

  double ok = 0;
  double ng = 1;
  for (int ii = 0; ii < 30; ii++) {
    double mid = (ok + ng) / 2;

    std::multiset<double> ms;
    for (int i = k; i <= n; i++) {
      ms.insert(sum[i] - i * mid);
    }

    bool found = false;
    for (int i = 0; i < n; i++) {
      if (sum[i] - i * mid <= *ms.rbegin()) {
        found = true;
      }
      ms.erase(ms.find(sum[i + k] - mid * (i + k)));
      ms.insert(sum[i + n + 1] - mid * (i + n + 1));
    }
    
    (found ? ok : ng) = mid;
  }

  printf("%.20f\n", ok);
}
0