結果

問題 No.576 E869120 and Rings
ユーザー rpy3cpprpy3cpp
提出日時 2017-10-14 23:05:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 1,500 ms
コード長 1,546 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 174,868 KB
実行使用メモリ 27,720 KB
最終ジャッジ日時 2024-04-28 19:44:40
合計ジャッジ時間 9,805 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 458 ms
26,248 KB
testcase_01 AC 494 ms
26,244 KB
testcase_02 AC 480 ms
26,504 KB
testcase_03 AC 499 ms
26,120 KB
testcase_04 AC 416 ms
26,380 KB
testcase_05 AC 417 ms
26,540 KB
testcase_06 AC 430 ms
26,120 KB
testcase_07 AC 422 ms
26,504 KB
testcase_08 AC 220 ms
25,512 KB
testcase_09 AC 252 ms
25,548 KB
testcase_10 AC 236 ms
25,564 KB
testcase_11 AC 220 ms
25,844 KB
testcase_12 AC 205 ms
25,684 KB
testcase_13 AC 183 ms
25,008 KB
testcase_14 AC 233 ms
27,720 KB
testcase_15 AC 182 ms
27,532 KB
testcase_16 AC 154 ms
23,660 KB
testcase_17 AC 237 ms
27,640 KB
testcase_18 AC 193 ms
25,484 KB
testcase_19 AC 203 ms
25,456 KB
testcase_20 AC 198 ms
25,668 KB
testcase_21 AC 185 ms
25,764 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool is_valid(double mid, int K, int N, const vector<double> & As){
    vector<double> Bs(2 * N, 0);
    for (int i = 0; i < N; ++i) Bs[i] = As[i] - mid;
    for (int i = 0; i < N; ++i) Bs[N + i] = Bs[i];
    vector<double> Cs(2 * N + 1, 0);
    for (int i = 0; i < 2 * N; ++i) Cs[i + 1] = Cs[i] + Bs[i];
    deque<pair<double, int>> window;
    for (int i = K; i <= N; ++i){
        while ((not window.empty()) and window.back().first < Cs[i]) window.pop_back();
        window.emplace_back(Cs[i], i);
    }
    if (window.front().first >= Cs[0]) return true;
    for (int i = 1; i < N; ++i){
        if (window.front().second < K + i) window.pop_front();
        while ((not window.empty()) and window.back().first < Cs[i + N]) window.pop_back();
        window.emplace_back(Cs[i + N], i + N);
        if (window.front().first >= Cs[i]) return true;
    }
    return false;
}


double solve(int K, int N, const vector<double> & As){
    double eps = 1e-7;
    double OK = 0.0;
    double NG = 1.0 + eps;
    while (OK + eps < NG){
        double mid = (OK + NG)/2.0;
        if (is_valid(mid, K, N, As)){
            OK = mid;
        }else{
            NG = mid;
        }
    }
    return OK;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<double> As(N, 0);
    for (int i = 0; i < N; ++i) As[i] = (double)(S[i] - '0');
    cout.precision(8);
    cout << fixed << solve(K, N, As) << endl;
    return 0;
}
0