結果

問題 No.576 E869120 and Rings
ユーザー beetbeet
提出日時 2019-03-05 10:48:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,884 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 208,936 KB
実行使用メモリ 47,212 KB
最終ジャッジ日時 2023-09-05 18:42:16
合計ジャッジ時間 37,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,293 ms
45,480 KB
testcase_09 AC 1,248 ms
45,240 KB
testcase_10 AC 1,200 ms
46,408 KB
testcase_11 AC 1,277 ms
44,820 KB
testcase_12 AC 1,398 ms
42,800 KB
testcase_13 AC 1,190 ms
47,212 KB
testcase_14 AC 1,327 ms
42,824 KB
testcase_15 AC 1,308 ms
46,952 KB
testcase_16 AC 1,269 ms
46,924 KB
testcase_17 AC 1,199 ms
44,992 KB
testcase_18 AC 1,133 ms
46,996 KB
testcase_19 AC 1,246 ms
44,792 KB
testcase_20 AC 1,286 ms
46,600 KB
testcase_21 AC 1,110 ms
46,712 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T, typename F>
struct RangeSlide{
  vector<size_t> ls,rs;
  vector<T> vs;
  F cmp;
  RangeSlide(vector<T> vs,F cmp):vs(vs),cmp(cmp){}

  void add_range(size_t l,size_t r){
    ls.emplace_back(l);
    rs.emplace_back(r);
  }
  
  vector<size_t> build(){
    deque<size_t> deq;
    vector<size_t> res;
    for(size_t i=0,l=0,r=0;i<ls.size();i++){
      if(r<=ls[i]){
        deq.clear();
        l=r=ls[i];
      }
      while(r<rs[i]){
        while(!deq.empty()&&!cmp(vs[deq.back()],vs[r])) deq.pop_back();
        deq.emplace_back(r++);
      }
      while(l<ls[i]){
        if(deq.front()==l++) deq.pop_front();
      }
      res.emplace_back(deq.front());
    }
    return res;
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;  
  vector<int> a(n);
  for(int i=0;i<n;i++) a[i]=s[i]-'0';
  
  using D = double;
  auto check=
    [&](D x)->int{
      vector<D> b(n);
      for(int i=0;i<n;i++) b[i]=a[i]-x;
      
      vector<D> sm(n*2+1,0);
      for(int i=0;i<n*2;i++) 
        sm[i+1]=sm[i]+b[i%n];

      auto cmp=[](D a,D b){return a<b;};      
      RangeSlide<D, decltype(cmp)> rs(sm,cmp);
      for(int i=0;i<n;i++)
        rs.add_range(i,i+n-k+1);      

      auto res=rs.build();      
      for(int i=0;i<n;i++)
        if(sm[n+i]>sm[res[i]]) return 1;
      return 0;
    };

  D L=0,R=1;
  for(int k=0;k<50;k++){
    D M=(L+R)/2;
    if(check(M)) L=M;
    else R=M;
  }
  cout<<L<<endl;
  return 0;
}
0