QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751493#9540. Double 11hos_lyricTL 5510ms7184kbC++143.8kb2024-11-15 19:08:552024-11-15 19:08:56

Judging History

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

  • [2024-11-15 19:08:56]
  • 评测
  • 测评结果:TL
  • 用时:5510ms
  • 内存:7184kb
  • [2024-11-15 19:08:55]
  • 提交

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")


template <class T, class Cost> struct MonotoneMinDP {
  int n;
  Cost cost;
  vector<T> ts;
  vector<int> par;
  MonotoneMinDP() {}
  MonotoneMinDP(int n_, Cost cost_) : n(n_), cost(cost_) {
    ts.assign(n + 1, T());
    par.assign(n + 1, -1);
    // from que[k].first to [que[k].second, que[k + 1].second)
    vector<pair<int, int>> que(n + 1);
    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) {}
      par[i] = que[head].first;
      ts[i] = ts[par[i]] + cost(par[i], i);
      int j = -1;
      for (; head < tail && que[tail - 1].second >= (j = when(que[tail - 1].first, i)); --tail) {}
      if (head == tail) j = i + 1;
      que[tail++] = make_pair(i, j);
    }
  }
  int when(int i0, int i1) const {
    int lo = i1, hi = n + 1;
    for (; lo + 1 < hi; ) {
      const int mid = (lo + hi) / 2;
      ((ts[i0] + cost(i0, mid) < ts[i1] + cost(i1, mid)) ? lo : hi) = mid;
    }
    return hi;
  }
};
template <class T, class Cost> MonotoneMinDP<T, Cost> monotoneMinDP(int n, Cost cost) {
  return MonotoneMinDP<T, Cost>(n, cost);
}


template <class D, class F> auto goldenMax(D a, D b, int numIters, F f) {
  constexpr D GOLD = (3.0L - sqrt(5.0L)) / 2.0L;
  D c = a + GOLD * (b - a), d = b - GOLD * (b - a);
  auto fc = f(c), fd = f(d);
  for (int iter = 0; iter < numIters; ++iter) {
    if (fc < fd) { a = c; c = d; d = b - GOLD * (b - a); fc = fd; fd = f(d); }
    else         { b = d; d = c; c = a + GOLD * (b - a); fd = fc; fc = f(c); }
  }
  return make_pair(fc, 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];
    }
    
    auto cost = [&](int l, int r) -> Double {
      return sqrt((Double)((r - l) * (SSum[r] - SSum[l])));
    };
    auto lag = [&](const Double pena) {
      return monotoneMinDP<Double>(N, [&](int l, int r) -> Double {
        return cost(l, r) + pena;
      });
    };
    // cost <= sqrt(N SSum[N]) <= (2*10^5) * sqrt(10^5)
    const auto res = goldenMax(-2e8L, +2e8L, 200, [&](const Double pena) -> Double {
      const auto m = lag(pena);
// cerr<<pena<<": "<<m.ts<<" "<<m.par<<" "<<(m.ts[N]-M*pena)<<endl;
      return m.ts[N] - M * pena;
    });
    
    printf("%.20Lf\n", res.first);
  }
  return 0;
}

详细

Test #1:

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

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: 3860kb

input:

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

output:

22.59162536651412858495

result:

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

Test #3:

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

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: 3864kb

input:

7 1
10 47 53 9 83 33 15

output:

41.83300132670365201193

result:

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

Test #6:

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

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

233.90165455194358382074

result:

ok found '233.901654552', expected '233.901654552', error '0.000000000'

Test #7:

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

input:

58 1
888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983

output:

1355.26528768356001819484

result:

ok found '1355.265287684', expected '1355.265287684', error '0.000000000'

Test #8:

score: 0
Accepted
time: 2ms
memory: 4024kb

input:

88 30
67117 31903 93080 85196 16438 97116 11907 72959 83651 41273 52873 81892 81468 51323 99992 58869 54258 7183 87358 90990 80596 41252 90769 82705 61434 8524 13575 10787 53950 96768 12062 34637 27806 70937 69653 28380 90236 3352 27537 3873 91006 89790 25369 91825 82734 5588 4539 74118 47098 84741 ...

output:

18791.47535409410011197906

result:

ok found '18791.475354094', expected '18791.475354094', error '0.000000000'

Test #9:

score: 0
Accepted
time: 45ms
memory: 3976kb

input:

987 59
5209 1618 7129 7700 893 6647 8231 3314 9844 1347 6789 2711 3968 7416 5864 9190 9564 8874 7357 2087 530 8754 7935 6772 3475 8206 2898 2717 9252 8686 6604 5188 7451 9977 9366 7618 6294 6454 3919 3232 8164 8403 8617 2191 5257 626 8554 1952 1727 4759 205 9453 3312 9387 4798 7774 7005 8892 3570 50...

output:

66075.50858705464684561548

result:

ok found '66075.508587055', expected '66075.508587055', error '0.000000000'

Test #10:

score: 0
Accepted
time: 15ms
memory: 3900kb

input:

572 529
48392 84311 16267 29255 52276 20511 75195 95522 64489 52229 74478 69766 41777 25148 59976 66512 62953 16779 69312 98832 96131 94700 46403 58028 12868 83503 80367 51036 63398 7509 55193 76715 29143 75925 89863 89244 5561 21242 9047 89763 78016 86274 11382 88520 72343 29729 70986 86600 43707 7...

output:

119849.32268175806107279868

result:

ok found '119849.322681758', expected '119849.322681758', error '0.000000000'

Test #11:

score: 0
Accepted
time: 348ms
memory: 4088kb

input:

6133 2231
2292 4026 3420 3246 5243 41 4223 468 682 5008 1497 584 1573 7049 5848 4129 5555 9957 9311 7225 6065 9498 3569 1695 717 1968 9690 7557 8700 9427 5142 371 8788 2260 9576 2674 4322 7448 5829 9123 982 7591 438 1590 9459 5982 5002 243 4144 4254 9585 9988 6745 3691 9602 2297 9518 1181 9814 1746 ...

output:

406852.36690047162079508780

result:

ok found '406852.366900472', expected '406852.366900471', error '0.000000000'

Test #12:

score: 0
Accepted
time: 424ms
memory: 4216kb

input:

8384 5123
19058 18998 87373 34122 75328 47694 7628 72373 15038 82392 99284 70202 49919 24589 3369 42325 8281 56682 20694 78018 67433 34318 26086 37124 18668 94430 78732 53794 58279 21730 60156 95172 58849 10021 70991 26522 88420 92248 63779 33077 16703 80111 94041 85804 3110 21282 12757 69593 53872 ...

output:

1764954.76112867261917926953

result:

ok found '1764954.761128673', expected '1764954.761128677', error '0.000000000'

Test #13:

score: 0
Accepted
time: 5180ms
memory: 7068kb

input:

92842 83212
71466 9482 98728 78471 22915 2470 5999 53211 25994 3996 11349 30511 56448 17277 78308 18316 42069 38636 63127 26256 63985 57249 58305 64366 17839 28518 18980 95945 36316 6076 69530 96509 6940 6039 56048 41847 82118 41054 49670 95896 45891 74636 90736 75413 27251 87730 68344 66202 71879 5...

output:

19558873.68887016989901894704

result:

ok found '19558873.688870169', expected '19558873.688863300', error '0.000000000'

Test #14:

score: 0
Accepted
time: 5510ms
memory: 7184kb

input:

93773 73078
12212 18977 10701 17909 16643 1406 15608 19767 11321 4708 10418 5834 10141 18240 12668 2694 11528 16150 8201 793 9736 15133 17474 6052 830 8574 1473 6393 11680 9784 16406 3428 10520 6431 7941 3167 17474 16569 19046 9595 7858 12512 7204 414 13548 7490 9887 9184 4298 1124 8330 749 12122 14...

output:

8833985.13992472119934973307

result:

ok found '8833985.139924722', expected '8833985.139919622', error '0.000000000'

Test #15:

score: -100
Time Limit Exceeded

input:

93116 27259
19231 23827 31564 18589 37658 17067 9191 26550 24206 13382 31064 1668 35186 10253 21408 16584 23217 11706 6324 16856 1642 28253 25916 39965 9455 35610 19925 15446 23558 36649 20624 35732 32683 33877 35121 26492 33868 35902 3312 18504 12747 31575 827 16198 22080 8616 16114 11479 1973 3457...

output:


result: