結果

問題 No.576 E869120 and Rings
ユーザー nebukuro09nebukuro09
提出日時 2018-06-21 16:52:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,489 ms / 1,500 ms
コード長 1,163 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 202,500 KB
実行使用メモリ 17,544 KB
最終ジャッジ日時 2023-09-13 07:35:30
合計ジャッジ時間 25,562 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,138 ms
16,956 KB
testcase_01 AC 1,392 ms
17,060 KB
testcase_02 AC 1,480 ms
16,728 KB
testcase_03 AC 1,489 ms
16,724 KB
testcase_04 AC 1,106 ms
16,800 KB
testcase_05 AC 1,122 ms
16,728 KB
testcase_06 AC 1,378 ms
17,060 KB
testcase_07 AC 1,486 ms
16,760 KB
testcase_08 AC 816 ms
16,496 KB
testcase_09 AC 661 ms
16,544 KB
testcase_10 AC 773 ms
16,660 KB
testcase_11 AC 736 ms
16,492 KB
testcase_12 AC 685 ms
16,492 KB
testcase_13 AC 658 ms
16,220 KB
testcase_14 AC 710 ms
17,516 KB
testcase_15 AC 474 ms
17,504 KB
testcase_16 AC 472 ms
15,484 KB
testcase_17 AC 670 ms
17,544 KB
testcase_18 AC 734 ms
16,532 KB
testcase_19 AC 737 ms
16,464 KB
testcase_20 AC 622 ms
16,656 KB
testcase_21 AC 739 ms
16,552 KB
testcase_22 AC 2 ms
5,616 KB
testcase_23 AC 2 ms
5,744 KB
testcase_24 AC 2 ms
5,612 KB
testcase_25 AC 2 ms
5,716 KB
testcase_26 AC 2 ms
5,604 KB
testcase_27 AC 2 ms
5,740 KB
testcase_28 AC 2 ms
5,612 KB
testcase_29 AC 2 ms
5,704 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(_, 100) {
        double mid = (hi + lo) / 2;
        (check(mid) ? lo : hi) = mid;
    }

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