QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#710668 | #9540. Double 11 | definieren | WA | 2ms | 12080kb | C++14 | 5.1kb | 2024-11-04 20:58:14 | 2024-11-04 20:58:14 |
Judging History
answer
#include <bits/stdc++.h>
#define fir first
#define sec second
#ifdef LOCAL
#define dbg(x) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << '\n'
#define dpi(x, y) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << " ; " << "the " << #y << " = " << y << '\n'
#define dbgf(fmt, args...) fprintf(stderr, fmt, ##args)
#else
#define dbg(x) void()
#define dpi(x, y) void()
#define dbgf(fmt, args...) void()
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ldb = long double;
using i128 = __int128_t;
using ui128 = __uint128_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vpii = vector<pii>;
bool Mbe;
constexpr int MOD = 998244353;
template<typename T> T Norm(T a, T p = MOD) { return (a % p + p) % p; }
template<typename T> T add(T a, T b, T p = MOD) { return (a + b >= p) ? (a + b - p) : (a + b); }
template<typename T> T del(T a, T b, T p = MOD) { return (a - b < 0) ? (a - b + p) : (a - b); }
template<typename T> T mul(T a, T b, T p = MOD) { return 1ll * a * b % p; }
template<typename T> T cadd(T &a, T b, T p = MOD) { return a = add(a, b, p); }
template<typename T> T cdel(T &a, T b, T p = MOD) { return a = del(a, b, p); }
template<typename T> T cmul(T &a, T b, T p = MOD) { return a = mul(a, b, p); }
template<typename T> bool cmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> bool cmin(T &a, T b) { return a > b ? a = b, true : false; }
template<typename T> T DivFloor(T a, T b) { return a >= 0 ? a / b : (a - b + 1) / b; }
template<typename T> T DivCeil(T a, T b) { return a >= 0 ? (a + b - 1) / b : a / b; }
namespace FastIO {
constexpr int LEN = 1 << 20;
char in[LEN + 1], out[LEN + 1];
char *pin = in, *pout = out, *ein = in, *eout = out + LEN;
char gc() { return pin == ein && (ein = (pin = in) + fread(in, 1, LEN, stdin), ein == in) ? EOF : *pin ++; }
void pc(char c) { pout == eout && (fwrite(out, 1, LEN, stdout), pout = out); (*pout ++) = c; return; }
struct Flush { ~Flush() { fwrite(out, 1, pout - out, stdout); pout = out; return; } } _flush;
template<typename T> T Read() {
T x = 0; int f = 1; char ch = gc();
while (ch < '0' || ch > '9') f = (ch == '-' ? (~f + 1) : f), ch = gc();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
return x * f;
}
void Read(char *s) {
char ch = gc();
while (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t') ch = gc();
while ((ch != EOF) && !(ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t')) *s = ch, s ++, ch = gc();
*s = '\0'; return;
}
template<typename T> void Read(T &x) { x = Read<T>(); return; }
template<typename T, typename ...Args>
void Read(T &x, Args &...args) { Read(x), Read(args...); return; }
template<typename T> void Write(T x) {
static char stk[40]; int tp = 0;
if (x < 0) pc('-'), x = ~x + 1;
do stk[tp++] = x % 10 + 48, x /= 10; while (x);
while (tp --) pc(stk[tp]);
return;
}
void Write(char ch) { pc(ch); return; }
void Write(const char *s) {
while (*s != '\0') pc(*s), s ++;
return;
}
void Puts(const char *s) {
Write(s), pc('\n'); return;
}
template<typename T, typename ...Args>
void Write(T x, Args ...args) { Write(x), Write(args...); return; }
}
using FastIO::Read;
using FastIO::Write;
using FastIO::Puts;
#define getchar FastIO::gc
#define putchar FastIO::pc
constexpr int N = 2e5 + 5;
constexpr ldb eps = 1e-11;
int n, m, a[N];
ll s[N];
pair<ldb, int> f[N];
bool check(ldb x) {
static struct Decision { int l, r, opt; } Q[N];
int head = 1, tail = 0; Q[++ tail] = {1, n, 0}, f[0] = make_pair((ldb)0, 0);
auto val = [&](int l, int r) { return sqrtl((r - l) * (s[r] - s[l])) - x; };
for (int i = 1; i <= n; i ++) {
while (head <= tail && Q[head].r < i) head ++;
Q[head].l = i, f[i].sec = f[Q[head].opt].sec + 1;
f[i].fir = f[Q[head].opt].fir + val(Q[head].opt, i);
while (head <= tail &&
f[Q[tail].opt].fir + val(Q[tail].opt, Q[tail].l)
> f[i].fir + val(i, Q[tail].l) ) tail --;
if (head <= tail) {
int l = Q[tail].l, r = Q[tail].r,
opt = Q[tail].opt, ans = r + 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (f[opt].fir + val(opt, mid)
> f[i].fir + val(i, mid) ) ans = mid, r = mid - 1;
else l = mid + 1;
}
Q[tail].r = ans - 1;
if (ans <= n) Q[++ tail] = {ans, n, i};
} else Q[++ tail] = {i + 1, n, i};
}
return f[n].sec <= m;
}
void slv() {
Read(n, m);
for (int i = 1; i <= n; i ++) Read(a[i]);
partial_sum(a + 1, a + n + 1, s + 1);
ldb l = - 2e15, r = 0;
while (fabsl(r - l) > eps) {
ldb mid = (l + r) / 2;
if (check(mid)) l = mid;
else r = mid;
}
check(l), printf("%.9Lf\n", f[n].fir + l * m);
return;
}
void clr() {
return;
}
bool Med;
int main() {
#ifdef LOCAL
freopen("!in.in", "r", stdin);
freopen("!out.out", "w", stdout);
fprintf(stderr, "%.3lf Mb\n", fabs((&Mbe - &Med) / 1048576.0));
#endif
int T = 1;
// int T = Read<int>();
while (T --) slv(), clr();
#ifdef LOCAL
fprintf(stderr, "%d ms\n", (int)clock());
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9976kb
input:
4 2 1 2 3 4
output:
6.191147130
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 10032kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.591625367
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 12080kb
input:
1 1 1
output:
1.000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 10036kb
input:
1 1 100000
output:
316.227766017
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: 0
Accepted
time: 2ms
memory: 9916kb
input:
7 1 10 47 53 9 83 33 15
output:
41.833001327
result:
ok found '41.833001327', expected '41.833001327', error '0.000000000'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 10032kb
input:
8 5 138 1702 119 1931 418 1170 840 1794
output:
242.457855568
result:
wrong answer 1st numbers differ - expected: '233.9016546', found: '242.4578556', error = '0.0365803'