結果

問題 No.576 E869120 and Rings
ユーザー Min_25Min_25
提出日時 2017-10-14 00:30:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 1,500 ms
コード長 1,665 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 82,796 KB
実行使用メモリ 4,752 KB
最終ジャッジ日時 2023-08-11 00:39:06
合計ジャッジ時間 3,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
4,492 KB
testcase_01 AC 60 ms
4,584 KB
testcase_02 AC 76 ms
4,564 KB
testcase_03 AC 77 ms
4,752 KB
testcase_04 AC 77 ms
4,476 KB
testcase_05 AC 78 ms
4,492 KB
testcase_06 AC 67 ms
4,496 KB
testcase_07 AC 80 ms
4,576 KB
testcase_08 AC 83 ms
4,604 KB
testcase_09 AC 62 ms
4,532 KB
testcase_10 AC 76 ms
4,728 KB
testcase_11 AC 74 ms
4,536 KB
testcase_12 AC 72 ms
4,652 KB
testcase_13 AC 55 ms
4,636 KB
testcase_14 AC 97 ms
4,492 KB
testcase_15 AC 23 ms
4,748 KB
testcase_16 AC 66 ms
4,528 KB
testcase_17 AC 81 ms
4,576 KB
testcase_18 AC 50 ms
4,440 KB
testcase_19 AC 50 ms
4,536 KB
testcase_20 AC 58 ms
4,504 KB
testcase_21 AC 50 ms
4,508 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <stack>
#include <queue>

#include <tuple>

#define getchar getchar_unlocked
#define putchar putchar_unlocked

#define _rep(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)

using namespace std;

using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double;

int get_int() {
  int c, n;
  while ((c = getchar()) < '0');
  n = c - '0';
  while ((c = getchar()) >= '0') n = n * 10 + (c - '0');
  return n;
}

void solve() {
  int N, K;
  while (~scanf("%d %d", &N, &K)) {
    char str[1000010]; scanf("%s", str);
    const int l = strlen(str);
    copy(str, str + l, str + l);
    double lo = 0.0, hi = 1.0;

    rep(_, 50) {
      double mid = (lo + hi) / 2.;
      double s = 0.0, best = 0, t = 0.0;
      rep(i, K) s += str[i] - '0' - mid;
      bool ok = false;
      rep(i, K, 2 * l) {
        if (s > best) {
          ok = true;
          break;
        }
        s += str[i] - '0' - mid;
        t += str[i - K] - '0' - mid;
        best = min(best, t);
      }
      if (ok) lo = mid;
      else hi = mid;
    }
    printf("%.10f\n", lo);
  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0