結果

問題 No.576 E869120 and Rings
ユーザー chocorusk
提出日時 2019-07-08 00:22:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 870 ms / 1,500 ms
コード長 1,264 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 101,972 KB
実行使用メモリ 13,348 KB
最終ジャッジ日時 2024-10-05 21:35:25
合計ジャッジ時間 14,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, k;
    cin>>n>>k;
    string a;
    cin>>a;
    a+=a;
    double x1=0, x2=1;
    for(int t=0; t<50; t++){
        double x=(x1+x2)/2;
        double s[1000010];
        s[0]=0;
        deque<int> deq;
        for(int i=0; i<2*n; i++){
            if(a[i]=='1') s[i+1]=s[i]+1-x;
            else s[i+1]=s[i]-x;
        }
        bool ok=0;
        for(int i=k; i<=2*n; i++){
            while(!deq.empty()){
                if(s[deq.back()]<=s[i]) deq.pop_back();
                else break;
            }
            deq.push_back(i);
            if(i>=n && s[deq.front()]>=s[i-n]){
                ok=1;
                break;
            }
            if(deq.front()==i-n+k) deq.pop_front();
        }
        if(ok) x1=x;
        else x2=x;
    }
    printf("%.7lf\n", x1);
    return 0;
}
0