結果

問題 No.576 E869120 and Rings
ユーザー ei1333333ei1333333
提出日時 2017-10-13 23:02:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,007 ms / 1,500 ms
コード長 1,381 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 208,408 KB
実行使用メモリ 26,340 KB
最終ジャッジ日時 2023-08-11 00:31:44
合計ジャッジ時間 24,532 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 983 ms
24,524 KB
testcase_01 AC 938 ms
24,296 KB
testcase_02 AC 984 ms
24,300 KB
testcase_03 AC 1,007 ms
24,280 KB
testcase_04 AC 986 ms
24,380 KB
testcase_05 AC 975 ms
24,404 KB
testcase_06 AC 961 ms
24,296 KB
testcase_07 AC 966 ms
24,184 KB
testcase_08 AC 850 ms
24,360 KB
testcase_09 AC 846 ms
24,220 KB
testcase_10 AC 861 ms
24,448 KB
testcase_11 AC 823 ms
24,452 KB
testcase_12 AC 821 ms
24,488 KB
testcase_13 AC 822 ms
25,504 KB
testcase_14 AC 886 ms
25,468 KB
testcase_15 AC 710 ms
25,412 KB
testcase_16 AC 823 ms
26,340 KB
testcase_17 AC 858 ms
25,456 KB
testcase_18 AC 814 ms
24,284 KB
testcase_19 AC 805 ms
24,476 KB
testcase_20 AC 804 ms
24,252 KB
testcase_21 AC 812 ms
24,324 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;

std::vector< int > slideMinimum(const std::vector< double > &a, int k)
{
  int n = a.size();
  std::deque< int > deq;
  std::vector< int > res;
  for(int i = 0; i < n; i++) {
    while(deq.size() && a[deq.back()] >= a[i]) deq.pop_back();
    deq.push_back(i);
    if(i - k + 1 >= 0) {
      res.push_back(deq.front());
      if(deq.front() == i - k + 1) deq.pop_front();
    }
  }
  return res;
}


int main()
{
  int64 N, K;
  string A;

  cin >> N >> K;
  cin >> A;

  auto check = [&](double k)
  {
    int sum = 0;
    queue< double > lazy;
    lazy.emplace(0.0);
    vector< double > all(N + N + N, 1e9);
    int last = 114514;
    for(int i = 0; i < N + N; i++) {
      if(K <= i + 1) {
        all[i + N - 1] = lazy.front();
        last = min(last, i);
        lazy.pop();
      }
      sum += A[i % N] - '0';
      lazy.emplace(sum - (i + 1) * k);
    }
    auto p = slideMinimum(all, N);

    sum = 0;
    for(int i = 0; i < N + N; i++) {
      sum += A[i % N] - '0';
      if(last <= i) {
        if(all[p[i]] <= sum - (i + 1) * k) return (true);
      }
    }
    return (false);
  };

  double low = 0.0, high = 1.0;
  for(int i = 0; i < 20; i++) {
    double mid = (low + high) * 0.5;
    if(check(mid)) low = mid;
    else high = mid;
  }
  cout << fixed << setprecision(10) << low << endl;

}
0