QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#752196#9540. Double 11hos_lyricWA 0ms3940kbC++143.7kb2024-11-15 22:49:562024-11-15 22:49:56

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 22:49:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3940kb
  • [2024-11-15 22:49:56]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


Int counter=0;

template <class T> struct MonotoneMinDP {
  int n;
  vector<T> ts;
  vector<int> par;
  vector<pair<int, int>> que;
  template <class Cost> void run(int n_, Cost cost) {
    auto get = [&](int l, int r) -> T {
// ++counter;assert(0<=l);assert(l<r);assert(r<=n);
      return ts[l] + cost(l, r);
    };
    n = n_;
    ts.resize(n + 1);
    ts[0] = T();
    par.resize(n + 1);
    for (int i = 0; i <= n; ++i) par[i] = -1;
    que.resize(n + 1);
    // from que[k].first to [que[k].second, que[k + 1].second)
    int head = 0, tail = 1;
    que[0] = make_pair(0, 1);
    for (int i = 1; i <= n; ++i) {
      for (; head + 1 < tail && que[head + 1].second <= i; ++head) {}
      ts[i] = get(par[i] = que[head].first, i);
      for (int rr = n + 1; ; --tail) {
        if (head == tail) {
          que[tail++] = make_pair(i, i + 1);
          break;
        }
        const int l = que[tail - 1].first, r = que[tail - 1].second;
        if (i >= r || get(l, r) < get(i, r)) {
          int lo = max(i + 1, r), hi = rr;
          for (; lo + 1 < hi; ) {
            const int mid = (lo + hi) / 2;
            ((get(l, mid) < get(i, mid)) ? lo : hi) = mid;
          }
          if (hi <= n) que[tail++] = make_pair(i, hi);
          break;
        } else {
          rr = r;
        }
      }
    }
  }
  T all() const {
    return ts[n];
  }
  int countSteps() const {
    int c = 0;
    for (int i = n; i; i = par[i]) ++c;
    return c;
  }
};

using Double = long double;

int N, M;
vector<Int> S;

int main() {
  for (; ~scanf("%d%d", &N, &M); ) {
    S.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &S[i]);
    }
    sort(S.begin(), S.end());
    
    vector<Int> SSum(N + 1, 0);
    for (int i = 0; i < N; ++i) {
      SSum[i + 1] = SSum[i] + S[i];
    }
    
    // cost <= sqrt(N SSum[N]) <= (2*10^5) * sqrt(10^5)
    Double lo = -100, hi = +2e8L;
    Double ans = 0;
    MonotoneMinDP<Double> f;
    for (int iter = 0; iter < 60; ++iter) {
      const Double mid = (lo + hi) / 2;
      f.run(N, [&](int l, int r) -> Double {
        return sqrt((Double)((r - l) * (SSum[r] - SSum[l]))) + mid;
      });
// cerr<<mid<<" "<<f.all()<<" "<<f.countSteps()<<" "<<(f.all()-M*mid)<<" "<<f.ts<<" "<<f.par<<endl;
      chmax(ans, f.all() - M * mid);
      ((f.countSteps() >= M) ? lo : hi) = mid;
    }
cerr<<"counter = "<<counter<<endl;
    
    printf("%.20Lf\n", ans);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

input:

4 2
1 2 3 4

output:

6.19114712955711948405

result:

ok found '6.191147130', expected '6.191147130', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

10 3
1 2 3 4 5 6 7 8 9 10

output:

22.59162536651412858668

result:

ok found '22.591625367', expected '22.591625367', error '0.000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

1 1
1

output:

1.00000000000000000000

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

1 1
100000

output:

316.22776601684017805383

result:

ok found '316.227766017', expected '316.227766017', error '0.000000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

7 1
10 47 53 9 83 33 15

output:

41.83300132670410675928

result:

ok found '41.833001327', expected '41.833001327', error '0.000000000'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3940kb

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

234.08877153182006734811

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '234.0887715', error = '0.0008000'