結果

問題 No.576 E869120 and Rings
ユーザー parukiparuki
提出日時 2017-10-16 11:59:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 1,500 ms
コード長 1,746 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 172,712 KB
実行使用メモリ 30,124 KB
最終ジャッジ日時 2023-08-11 06:47:09
合計ジャッジ時間 10,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
29,680 KB
testcase_01 AC 409 ms
29,940 KB
testcase_02 AC 414 ms
29,680 KB
testcase_03 AC 412 ms
29,676 KB
testcase_04 AC 410 ms
29,604 KB
testcase_05 AC 413 ms
29,732 KB
testcase_06 AC 409 ms
29,784 KB
testcase_07 AC 412 ms
29,900 KB
testcase_08 AC 250 ms
29,424 KB
testcase_09 AC 247 ms
29,616 KB
testcase_10 AC 252 ms
29,504 KB
testcase_11 AC 254 ms
29,620 KB
testcase_12 AC 252 ms
29,656 KB
testcase_13 AC 250 ms
29,344 KB
testcase_14 AC 253 ms
30,048 KB
testcase_15 AC 296 ms
29,340 KB
testcase_16 AC 312 ms
29,196 KB
testcase_17 AC 262 ms
30,124 KB
testcase_18 AC 257 ms
29,488 KB
testcase_19 AC 252 ms
29,620 KB
testcase_20 AC 252 ms
29,484 KB
testcase_21 AC 254 ms
29,600 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

vector<double> maxSlide(int length, vector<double> data, double minValue = -1) {
    int num = (int)data.size();
    deque<int> deq;
    vector<double> res(num, minValue);
    for (int i = 0; i < num; ++i) {
        while (!deq.empty() && data[deq.back()] <= data[i]) {
            deq.pop_back();
        }
        deq.push_back(i);
        if (i >= length - 1) {
            res[i - length + 1] = data[deq.front()];
            if (deq.front() == i - length + 1)deq.pop_front();
        }
    }
    return res;
}

int N, K, color[500005];

int check(double x) {
    vector<double> dat(N * 2);
    rep(i, N) {
        dat[i] = dat[i + N] = color[i] - x;
    }
    rep(i, 2 * N - 1)dat[i + 1] += dat[i];

    auto ma = maxSlide(N - K + 1, dat, INT_MIN);
    double pre = 0;
    rep(i, N) {
        if (ma[i + K - 1] >= pre)return 1;
        pre = dat[i];
    }
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> N >> K >> S;
    rep(i, N)color[i] = S[i] - '0';
    
    double l = 0, r = 1, x;
    rep(ITER, 20) {
        x = (l + r)*0.5;
        (check(x) ? l : r) = x;
    }
    cout << fixed << setprecision(20);
    cout << l << endl;
}
0