結果

問題 No.576 E869120 and Rings
ユーザー parukiparuki
提出日時 2017-10-16 11:59:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 487 ms / 1,500 ms
コード長 1,746 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 174,304 KB
実行使用メモリ 30,452 KB
最終ジャッジ日時 2024-04-28 23:26:52
合計ジャッジ時間 12,078 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 484 ms
29,928 KB
testcase_01 AC 482 ms
30,048 KB
testcase_02 AC 482 ms
30,056 KB
testcase_03 AC 487 ms
30,176 KB
testcase_04 AC 477 ms
30,048 KB
testcase_05 AC 480 ms
30,048 KB
testcase_06 AC 486 ms
29,920 KB
testcase_07 AC 485 ms
30,184 KB
testcase_08 AC 306 ms
29,928 KB
testcase_09 AC 302 ms
29,928 KB
testcase_10 AC 313 ms
29,932 KB
testcase_11 AC 304 ms
29,812 KB
testcase_12 AC 319 ms
29,928 KB
testcase_13 AC 303 ms
29,928 KB
testcase_14 AC 294 ms
30,288 KB
testcase_15 AC 442 ms
29,276 KB
testcase_16 AC 463 ms
29,272 KB
testcase_17 AC 316 ms
30,452 KB
testcase_18 AC 308 ms
29,796 KB
testcase_19 AC 305 ms
29,792 KB
testcase_20 AC 295 ms
29,920 KB
testcase_21 AC 302 ms
30,072 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 2 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;
#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