結果

問題 No.576 E869120 and Rings
ユーザー beetbeet
提出日時 2019-10-09 11:06:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 621 ms / 1,500 ms
コード長 1,902 bytes
コンパイル時間 2,507 ms
コンパイル使用メモリ 213,604 KB
実行使用メモリ 47,068 KB
最終ジャッジ日時 2024-04-27 16:25:02
合計ジャッジ時間 15,503 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 609 ms
43,068 KB
testcase_01 AC 621 ms
42,900 KB
testcase_02 AC 614 ms
42,964 KB
testcase_03 AC 620 ms
43,212 KB
testcase_04 AC 609 ms
42,776 KB
testcase_05 AC 603 ms
42,904 KB
testcase_06 AC 610 ms
42,904 KB
testcase_07 AC 603 ms
43,088 KB
testcase_08 AC 468 ms
44,992 KB
testcase_09 AC 481 ms
44,924 KB
testcase_10 AC 464 ms
46,556 KB
testcase_11 AC 479 ms
44,976 KB
testcase_12 AC 514 ms
43,036 KB
testcase_13 AC 429 ms
47,068 KB
testcase_14 AC 472 ms
42,768 KB
testcase_15 AC 462 ms
46,860 KB
testcase_16 AC 452 ms
46,992 KB
testcase_17 AC 431 ms
45,032 KB
testcase_18 AC 389 ms
45,556 KB
testcase_19 AC 458 ms
44,984 KB
testcase_20 AC 439 ms
46,980 KB
testcase_21 AC 457 ms
46,596 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 1 ms
6,944 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