結果

問題 No.576 E869120 and Rings
ユーザー parukiparuki
提出日時 2017-10-16 10:30:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,871 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 173,068 KB
実行使用メモリ 103,588 KB
最終ジャッジ日時 2024-04-28 23:20:16
合計ジャッジ時間 8,032 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 1,477 ms
103,340 KB
testcase_09 AC 1,428 ms
103,520 KB
testcase_10 AC 1,458 ms
103,552 KB
testcase_11 AC 1,432 ms
103,456 KB
testcase_12 AC 1,453 ms
103,512 KB
testcase_13 AC 1,444 ms
103,436 KB
testcase_14 AC 1,437 ms
103,348 KB
testcase_15 AC 1,454 ms
103,416 KB
testcase_16 AC 1,454 ms
103,444 KB
testcase_17 AC 1,424 ms
103,588 KB
testcase_18 AC 1,416 ms
103,516 KB
testcase_19 AC 1,438 ms
103,568 KB
testcase_20 AC 1,432 ms
103,304 KB
testcase_21 AC 1,426 ms
103,280 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 3 ms
6,948 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 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;

template<class Val, class Cmp>
class SparseTableRMQ {
public:
    SparseTableRMQ() {
    }
    SparseTableRMQ(Val *ar, int n) : n(n), data(n) {
        for (int i = 0; i < n; ++i) data[i] = ar[i];
        table = buildRMQ();
    }

    int queryPos(int l, int r) {
        int k = lgInt(r - l - 1);
        int lid = table[l + n*k], rid = table[r + n*k - (1 << k)];
        return (cmp(data[lid], data[rid])) ? lid : rid;
    }

    Val queryValue(int l, int r) {
        return data[queryPos(l, r)];
    }
private:
    int n;
    vector<Val> data;
    vector<int> table;
    Cmp cmp;
    int lgInt(int v) {
        static const unsigned b[] = { 0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000 };
        static const unsigned S[] = { 1, 2, 4, 8, 16 };
        int res = 0;
        for (int i = 4; i >= 0; i--) {
            if (v & b[i]) {
                v >>= S[i];
                res |= S[i];
            }
        }
        return res;
    }

    vector<int> buildRMQ() {
        int logn = 1;
        for (int k = 1; k < n; k *= 2) ++logn;
        vector<int> b(n*logn);
        for (int i = 0; i < n; ++i)b[i] = i;
        int cur = 0;
        for (int k = 1; k < n; k *= 2) {
            copy(b.begin() + cur, b.begin() + cur + n, b.begin() + cur + n);
            cur += n;
            for (int i = 0; i < n - k; ++i) {
                int idl = b[cur + i], idr = b[cur + i + k];
                if (cmp(data[idl], data[idr])) {
                    b[cur + i] = idl;
                } else {
                    b[cur + i] = idr;
                }
            }
        }
        return b;
    }
};

int N, K, color[500005];

double dat[500005*2];

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

    double pre = 0;
    rep(i, N) {
        double ma = rmq.queryValue(i + K - 1, i + N);
        if (ma - pre >= 0)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 << r << endl;
}
0