結果

問題 No.576 E869120 and Rings
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-21 08:29:18
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 881 ms / 1,500 ms
コード長 1,983 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 160,172 KB
実行使用メモリ 26,628 KB
最終ジャッジ日時 2023-09-03 22:47:31
合計ジャッジ時間 16,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 792 ms
24,700 KB
testcase_01 AC 703 ms
25,120 KB
testcase_02 AC 820 ms
25,564 KB
testcase_03 AC 881 ms
24,760 KB
testcase_04 AC 785 ms
25,820 KB
testcase_05 AC 797 ms
24,748 KB
testcase_06 AC 794 ms
25,280 KB
testcase_07 AC 825 ms
25,564 KB
testcase_08 AC 501 ms
26,628 KB
testcase_09 AC 485 ms
26,364 KB
testcase_10 AC 486 ms
26,360 KB
testcase_11 AC 427 ms
25,500 KB
testcase_12 AC 448 ms
25,320 KB
testcase_13 AC 378 ms
24,840 KB
testcase_14 AC 493 ms
25,544 KB
testcase_15 AC 168 ms
25,576 KB
testcase_16 AC 337 ms
25,320 KB
testcase_17 AC 431 ms
25,524 KB
testcase_18 AC 409 ms
25,208 KB
testcase_19 AC 407 ms
25,384 KB
testcase_20 AC 387 ms
25,524 KB
testcase_21 AC 412 ms
25,508 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


int N, K;
string A;

real[] sums;

// slide min
int qHead, qTail;
int[] q;

bool check(real r) {
  sums[0] = 0.0;
  foreach (i; 0 .. N * 2) {
    sums[i + 1] = sums[i] + ((A[i] == '1') ? (1.0 - r) : -r);
  }
  qHead = qTail = 0;
  foreach (i; K .. N * 2 + 1) {
    for (; qHead < qTail && sums[q[qTail - 1]] > sums[i - K]; --qTail) {}
    q[qTail++] = i - K;
    for (; qHead < qTail && q[qHead] < i - N; ++qHead) {}
    assert(qHead < qTail);
    if (sums[q[qHead]] <= sums[i]) {
      return true;
    }
  }
  return false;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readInt();
      A = readToken();
      A = A ~ A;
      sums = new real[N * 2 + 1];
      q = new int[N * 2 + 1];
      real lo = 0.0, hi = 1.0;
      foreach (_; 0 .. 20) {
        const mid = (lo + hi) / 2.0;
        (check(mid) ? lo : hi) = mid;
      }
      writefln("%.10f", lo);
    }
  } catch (EOFException e) {
  }
}
0