結果

問題 No.576 E869120 and Rings
ユーザー lam6er
提出日時 2025-03-20 20:28:15
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,574 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 275,960 KB
最終ジャッジ日時 2025-03-20 20:29:35
合計ジャッジ時間 6,178 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 1 -- * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    N, K = map(int, sys.stdin.readline().split())
    a_str = sys.stdin.readline().strip()
    a = [int(c) for c in a_str]
    array = a + a  # Double the array to handle circularity
    
    low = 0.0
    high = 1.0
    eps = 1e-15
    for _ in range(100):
        mid = (low + high) / 2
        # Compute the transformed array and prefix sum
        prefix = [0.0] * (2 * N + 1)
        for i in range(2 * N):
            prefix[i+1] = prefix[i] + (array[i] - mid)
        # Check using sliding window and deque
        found = False
        dq = deque()
        for i in range(2 * N):
            if i < K:
                continue  # j = i - K would be negative
            j = i - K
            # Maintain deque to add j candidates
            while dq and prefix[j] <= prefix[dq[-1]]:
                dq.pop()
            dq.append(j)
            # Remove elements out of the left boundary
            l = max(0, i - N)
            while dq and dq[0] < l:
                dq.popleft()
            if not dq:
                continue
            min_j = dq[0]
            current_sum = prefix[i+1] - prefix[min_j]
            if current_sum >= -eps:  # Allow for small negative due to precision
                found = True
                break
        if found:
            low = mid
        else:
            high = mid
    # Output with enough precision
    print("{0:.15f}".format(low).rstrip('0').rstrip('.') if '.' in "{0:.15f}".format(low) else "{0:.15f}".format(low))

if __name__ == "__main__":
    main()
0