結果

問題 No.576 E869120 and Rings
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-10-13 22:58:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,786 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 172,180 KB
実行使用メモリ 813,692 KB
最終ジャッジ日時 2024-04-28 17:39:10
合計ジャッジ時間 12,865 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
40,748 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 336 ms
40,804 KB
testcase_05 AC 404 ms
40,856 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 308 ms
40,696 KB
testcase_15 AC 311 ms
40,632 KB
testcase_16 AC 315 ms
40,476 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 12 ms
36,116 KB
testcase_23 AC 11 ms
36,084 KB
testcase_24 MLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
#define def make_pair(-1, -1)
template<class V, int NV> struct SegTree { //[l,r]
    V comp(V l, V r) { return max(l,r); };
    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int l, int r) { if (l>r)return def;l+=NV;r+=NV+1;V ret=def; while(l<r){
        if(l&1)ret=comp(ret,val[l++]);if(r&1)ret=comp(ret,val[--r]);l/=2;r/= 2;}return ret;}
    void update(int i, V v) { i+=NV;val[i]=v;while(i>1)i>>=1,val[i]=comp(val[i*2],val[i*2+1]); }
    void add(int i, V v) { update(i, val[i + NV] + v); }};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, K; string A;
SegTree<pair<double, int>,1<<20> st;
//---------------------------------------------------------------------------------------------------
int sm[1010101];
double f(int L, int R) {
    int md = (L + R) / 2;

    if (R - L < K) return 0;

    double res = 0;

    res = max(res, f(L, md));
    res = max(res, f(md, R));

    int up = 0, dn = 0;
    rep(i, md, R) {
        if (A[i] == '1') up++, dn++;
        else dn++;
        sm[i] = up;
        st.update(i, make_pair(1.0 * up / dn, i));
    }

    up = 0; dn = 0;
    rrep(i, md - 1, L) {
        if (A[i] == '1') up++, dn++;
        else dn++;

        int j = i + K - 1;
        auto p = st.get(j, R - 1);
        if (p.second < 0) continue;

        int upp = up + sm[p.second];
        int dnn = p.second - i + 1;

        res = max(res, 1.0 * upp / dnn);
    }

    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K >> A;
    
    A += A;
    /*double ans = 0;
    rep(L, 0, N) rep(len, K, N + 1) {
        int R = L + len;

        double up = 0, dn = 0;
        rep(i, L, R) {
            if (A[i] == '0') dn++;
            else up++, dn++;
        }

        ans = max(up / dn, ans);
    }
    printf("%.10f\n", ans);*/

    printf("%.10f\n", f(0, N * 2));
}
0