結果

問題 No.576 E869120 and Rings
ユーザー maspy
提出日時 2020-05-08 23:48:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 751 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 133,352 KB
最終ジャッジ日時 2024-07-04 01:17:49
合計ジャッジ時間 30,022 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 25 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
A = np.frombuffer(read().rstrip(), 'S1').astype(np.float64)

A = np.concatenate([A,A])

def test(A, x):
    # avg > x が可能
    A = A - x
    Acum = np.zeros(len(A) + 1, np.float64)
    Acum[1:] = np.cumsum(A)
    S = Acum[-1]
    if S > 0:
        return True
    if K <= (N // 2):
        B = np.minimum.accumulate(Acum)
        x = np.max(Acum[K:] - B[:-K])
        return x > 0
    B = np.maximum.accumulate(Acum)
    x = np.min(Acum[K:] - B[:-K])
    return S/2 - x > 0

vals = [0, 1]
for _ in range(22):
    x = sum(vals) / 2
    vals[1-test(A, x)] = x

print(vals[0])
0