QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#879879#9540. Double 11NianFengWA 0ms4212kbC++142.4kb2025-02-02 17:05:442025-02-02 17:05:45

Judging History

This is the latest submission verdict.

  • [2025-02-02 17:05:45]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 4212kb
  • [2025-02-02 17:05:44]
  • Submitted

answer

/* 年挽红枫,溪傍芦荻。*/

#ifdef DEBUG
#include <iostream>
#include <cmath>
#include <ctime>

bool Mbe;
void _Dihan();
#endif

#include <cstdio>
#include <cmath>

typedef long long i64;
typedef unsigned long long ull;
typedef double f32;
typedef long double ldb;
typedef __int128 i28;
typedef unsigned __int128 u28;

template <typename T> bool chkMx(T &x, T y) { return x < y ? x = y, true : false; }
template <typename T> bool chkMn(T &x, T y) { return x > y ? x = y, true : false; }

constexpr int N = 2e5 + 5;
constexpr ldb eps = 1e-15;

int n, m, a[N];

i64 pre[N];
struct Data {
   ldb f;
   int g;

   bool operator <=(const Data &x) const {
      return (f - eps < x.f && x.f < f + eps) ?
             g <= x.g : f <= x.f;
   }
   Data operator +(const ldb &k) const {
      return {f + k, g + 1};
   }
} dp[N];
Data w(int i, int j) {
   return dp[i] + sqrtl((pre[j] - pre[i]) * (j - i));
}

struct Node {
   int p, l, r;
} q[N];
int h, t;
int find(int l, int r, int x, int y) {
   int ans = r;

   while (l <= r) {
      int mid = l + r >> 1;

      if (w(x, mid) <= w(y, mid)) {
         ans = mid;
         r = mid - 1;
      } else
         l = mid + 1;
   }

   return ans;
}
void DP(ldb k) {
   q[h = t = 1] = {0, 1, n};

   for (int i = 1; i <= n; ++i) {
      while (q[h].r < i) ++h;
      q[h].l = i;

      dp[i] = w(q[h].p, i), dp[i].f -= k;

      while (h <= t && w(i, q[t].l) <= w(q[t].p, q[t].l))
         --t;

      if (h > t) q[++t] = {i, i + 1, n};
      else if (w(i, q[t].r) <= w(q[t].p, q[t].r)) {
         int tmp = find(q[t].l, q[t].r, i, q[t].p);

         q[t].r = tmp - 1, q[++t] = {i, tmp, n};
      } else if (q[t].r ^ n)
         q[t + 1] = {i, q[t].r + 1, n}, ++t;
   }
}

bool check(ldb k) {
   return DP(k), dp[n].g <= m;
}

int main() {

   scanf("%d%d", &n, &m);
   for (int i = 1; i <= n; ++i) {
      scanf("%d", a + i);

      pre[i] = pre[i - 1] + a[i];
   }

   ldb r = sqrtl(pre[n] * n), l = -r;

   while (r - l > eps) {
      ldb mid = (l + r) / 2;

      check(mid) ? l = mid : r = mid;
   }

   DP(l);

   printf("%.13Lf\n", dp[n].f + l * dp[n].g);

#ifdef DEBUG
   _Dihan();
#endif
   return 0;
}

#ifdef DEBUG
bool Med;
void _Dihan() {
   std::cerr << "Memory: " << abs(&Med - &Mbe) / 1048576.0 << " MB\n";
   std::cerr << "Time: " << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
}
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
1 2 3 4

output:

6.1911471295571

result:

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

Test #2:

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

input:

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

output:

22.5916253665141

result:

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

Test #3:

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

input:

1 1
1

output:

1.0000000000000

result:

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

Test #4:

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

input:

1 1
100000

output:

316.2277660168379

result:

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

Test #5:

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

input:

7 1
10 47 53 9 83 33 15

output:

41.8330013267038

result:

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

Test #6:

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

input:

8 5
138 1702 119 1931 418 1170 840 1794

output:

246.6646557241400

result:

wrong answer 1st numbers differ - expected: '233.9016546', found: '246.6646557', error = '0.0545657'