QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721981 | #9540. Double 11 | Max_s_xaM | WA | 2ms | 13400kb | C++17 | 4.4kb | 2024-11-07 17:21:41 | 2024-11-07 17:21:41 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <numeric>
#include <iomanip>
#include <cassert>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 2e5 + 10;
const lf eps = 1e-12;
int n, m, a[MAXN];
lf sum[MAXN];
inline lf Calc(int l, int r) { return sqrt((sum[r] - sum[l - 1]) * (r - l + 1)); }
int st[MAXN], head, tail;
int lt[MAXN], rt[MAXN];
struct Data
{
lf x; int y;
Data(lf _x = 0, int _y = 0) : x(_x), y(_y) {}
Data operator + (const lf u) const { return Data(x + u, y + 1); }
bool operator < (const Data &u) const { return abs(x - u.x) < eps ? y < u.y : x < u.x; }
bool operator > (const Data &u) const { return abs(x - u.x) < eps ? y > u.y : x > u.x; }
}f[MAXN];
inline bool Check(lf x)
{
st[head = tail = 1] = 0;
lt[0] = 1, rt[0] = n;
f[0] = Data(0, 0);
for (int i = 1; i <= n; i++)
{
while (head <= tail && rt[st[head]] < i) head++;
f[i] = f[st[head]] + (Calc(st[head] + 1, i) + x);
while (head <= tail && lt[st[tail]] > i && f[st[tail]] + Calc(st[tail] + 1, lt[st[tail]]) > f[i] + Calc(i + 1, lt[st[tail]])) tail--;
if (head > tail) st[++tail] = i, lt[i] = i + 1, rt[i] = n;
else if (f[st[tail]] + Calc(st[tail] + 1, rt[st[tail]]) > f[i] + Calc(i + 1, rt[st[tail]]))
{
int l = max(i + 1, lt[st[tail]]), r = rt[st[tail]], mid, res = l;
while (l <= r)
{
mid = l + r >> 1;
if (f[st[tail]] + Calc(st[tail] + 1, mid) > f[i] + Calc(i + 1, mid)) r = mid - 1, res = mid;
else l = mid + 1;
}
rt[st[tail]] = res - 1;
st[++tail] = i, lt[i] = res, rt[i] = n;
}
else lt[i] = rt[st[tail]] + 1, rt[i] = n, st[++tail] = i;
}
return f[n].y <= m;
}
int main()
{
// freopen("F.in", "r", stdin);
// freopen("F.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n), Read(m);
for (int i = 1; i <= n; i++) Read(a[i]);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
lf l = 0, r = 1e15, mid, ans = 0;
while (r - l > eps)
{
mid = (l + r) / 2;
if (Check(mid)) ans = mid, r = mid;
else l = mid;
}
Check(ans);
cout << fixed << setprecision(15);
cout << f[n].x - ans * m << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10580kb
input:
4 2 1 2 3 4
output:
6.191147129557120
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 13388kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.591625366514130
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 10400kb
input:
1 1 1
output:
1.000000000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 2ms
memory: 13244kb
input:
1 1 100000
output:
316.227766016837961
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 11620kb
input:
7 1 10 47 53 9 83 33 15
output:
41.833001326703780
result:
ok found '41.833001327', expected '41.833001327', error '0.000000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 9988kb
input:
8 5 138 1702 119 1931 418 1170 840 1794
output:
233.901654551943579
result:
ok found '233.901654552', expected '233.901654552', error '0.000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 11708kb
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.265287683559109
result:
ok found '1355.265287684', expected '1355.265287684', error '0.000000000'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 13400kb
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.485568588897877
result:
wrong answer 1st numbers differ - expected: '18791.4753541', found: '18791.4855686', error = '0.0000005'