結果

問題 No.576 E869120 and Rings
ユーザー maspymaspy
提出日時 2020-05-09 01:08:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 1,500 ms
コード長 1,179 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 74,128 KB
実行使用メモリ 22,012 KB
最終ジャッジ日時 2023-09-17 05:16:16
合計ジャッジ時間 5,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
21,044 KB
testcase_01 AC 180 ms
21,040 KB
testcase_02 AC 192 ms
21,180 KB
testcase_03 AC 206 ms
21,060 KB
testcase_04 AC 190 ms
21,168 KB
testcase_05 AC 192 ms
21,032 KB
testcase_06 AC 186 ms
21,060 KB
testcase_07 AC 196 ms
20,976 KB
testcase_08 AC 111 ms
21,028 KB
testcase_09 AC 115 ms
21,124 KB
testcase_10 AC 120 ms
21,228 KB
testcase_11 AC 110 ms
21,088 KB
testcase_12 AC 113 ms
21,060 KB
testcase_13 AC 108 ms
21,128 KB
testcase_14 AC 123 ms
21,220 KB
testcase_15 AC 78 ms
20,972 KB
testcase_16 AC 95 ms
22,012 KB
testcase_17 AC 111 ms
21,064 KB
testcase_18 AC 105 ms
21,048 KB
testcase_19 AC 104 ms
21,080 KB
testcase_20 AC 104 ms
21,180 KB
testcase_21 AC 104 ms
21,192 KB
testcase_22 AC 2 ms
7,772 KB
testcase_23 AC 2 ms
7,660 KB
testcase_24 AC 2 ms
7,660 KB
testcase_25 AC 2 ms
7,796 KB
testcase_26 AC 2 ms
7,656 KB
testcase_27 AC 2 ms
7,808 KB
testcase_28 AC 2 ms
7,644 KB
testcase_29 AC 2 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
using namespace std;

#define U 500010
double A[U + U];
double Acum[U + U];
int deq[U + U];
int N, K;

bool test(double x)
{
    Acum[0] = 0;
    for (int i = 0; i < N + N; i++)
    {
        Acum[i + 1] = Acum[i] + A[i] - x;
    }
    int l = 0;
    int r = 0;
    deq[0] = 0;
    for (int k = K; k <= N + N; k++)
    {
        while (deq[l] < k - N)
        {
            l++;
        }
        double x = Acum[k];
        if (x > Acum[deq[l]])
        {
            return true;
        }
        int i = k - K + 1;
        x = Acum[i];
        while (l <= r && Acum[deq[r]] > x)
        {
            r--;
        }
        r++;
        deq[r] = i;
    }
    return false;
}

int main()
{
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        char c;
        cin >> c;
        A[i] = c - 48.0;
        A[i + N] = c - 48.0;
    }
    double l = 0.0;
    double r = 1.0;
    for (int i = 0; i < 20; i++)
    {
        double m = (l + r) / 2;
        if (test(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }
    cout << fixed << setprecision(15) << l << endl;
    return 0;
}
0