結果

問題 No.576 E869120 and Rings
ユーザー nebukuro09nebukuro09
提出日時 2018-06-21 16:53:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,172 ms / 1,500 ms
コード長 1,162 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 204,624 KB
実行使用メモリ 17,596 KB
最終ジャッジ日時 2023-09-13 07:35:52
合計ジャッジ時間 20,821 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 937 ms
16,800 KB
testcase_01 AC 1,066 ms
17,012 KB
testcase_02 AC 1,172 ms
16,800 KB
testcase_03 AC 1,167 ms
16,812 KB
testcase_04 AC 916 ms
16,756 KB
testcase_05 AC 924 ms
16,808 KB
testcase_06 AC 1,055 ms
17,028 KB
testcase_07 AC 1,160 ms
16,744 KB
testcase_08 AC 644 ms
16,528 KB
testcase_09 AC 537 ms
16,564 KB
testcase_10 AC 613 ms
16,524 KB
testcase_11 AC 588 ms
16,544 KB
testcase_12 AC 555 ms
16,548 KB
testcase_13 AC 503 ms
16,232 KB
testcase_14 AC 563 ms
17,588 KB
testcase_15 AC 355 ms
17,460 KB
testcase_16 AC 387 ms
15,476 KB
testcase_17 AC 542 ms
17,596 KB
testcase_18 AC 563 ms
16,464 KB
testcase_19 AC 565 ms
16,532 KB
testcase_20 AC 509 ms
16,532 KB
testcase_21 AC 567 ms
16,476 KB
testcase_22 AC 2 ms
5,740 KB
testcase_23 AC 2 ms
5,724 KB
testcase_24 AC 2 ms
5,612 KB
testcase_25 AC 2 ms
5,540 KB
testcase_26 AC 2 ms
5,772 KB
testcase_27 AC 2 ms
5,724 KB
testcase_28 AC 2 ms
5,752 KB
testcase_29 AC 2 ms
5,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;

int N, K;
double A[501010];
double B[1010100];

bool check(double p) {
    B[0] = 0;
    REP(i, 2*N) B[i+1] = B[i] + A[i%N] - p;
    deque<double> q;
    
    REP2(i, K-1, N) {
        while (!q.empty() && q.back() < B[i+1])
            q.pop_back();
        q.push_back(B[i+1]);
    }
    
    if (q.front() >= B[0])
        return true;
    
    REP2(i, 1, N) {
        if (q.front() == B[i+K-1])
            q.pop_front();
        while (!q.empty() && q.back() < B[i+N])
            q.pop_back();
        q.push_back(B[i+N]);
        if (q.front() >= B[i])
            return true;
    }

    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K;
    string S; cin >> S;
    REP(i, N) A[i] = S[i] - '0';

    double hi = 1.0;
    double lo = 0.0;
    REP(_, 80) {
        double mid = (hi + lo) / 2;
        (check(mid) ? lo : hi) = mid;
    }

    cout.precision(20);
    cout << fixed  << hi << endl;    
}
0