結果

問題 No.576 E869120 and Rings
ユーザー beetbeet
提出日時 2019-10-09 11:06:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 684 ms / 1,500 ms
コード長 1,902 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 210,748 KB
実行使用メモリ 47,124 KB
最終ジャッジ日時 2023-08-09 22:03:23
合計ジャッジ時間 17,584 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 667 ms
42,860 KB
testcase_01 AC 669 ms
42,860 KB
testcase_02 AC 662 ms
43,012 KB
testcase_03 AC 684 ms
43,036 KB
testcase_04 AC 619 ms
43,020 KB
testcase_05 AC 684 ms
42,912 KB
testcase_06 AC 678 ms
42,700 KB
testcase_07 AC 679 ms
42,912 KB
testcase_08 AC 510 ms
44,792 KB
testcase_09 AC 519 ms
44,824 KB
testcase_10 AC 498 ms
46,440 KB
testcase_11 AC 468 ms
45,036 KB
testcase_12 AC 534 ms
43,068 KB
testcase_13 AC 457 ms
47,124 KB
testcase_14 AC 502 ms
43,040 KB
testcase_15 AC 521 ms
46,716 KB
testcase_16 AC 495 ms
47,104 KB
testcase_17 AC 479 ms
44,908 KB
testcase_18 AC 427 ms
45,364 KB
testcase_19 AC 482 ms
44,968 KB
testcase_20 AC 497 ms
46,888 KB
testcase_21 AC 488 ms
46,664 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
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;
  }
};
//END CUT HERE
#ifndef call_from_test
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 YUKI_576(){
  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<20;k++){
    D M=(L+R)/2;
    if(check(M)) L=M;
    else R=M;
  }
  cout<<L<<endl;
  return 0;
}
/*
  verified on 2019/05/27
  https://yukicoder.me/problems/no/576
*/

signed main(){
  YUKI_576();
  return 0;
}
#endif
0