QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710803#9540. Double 11definierenRE 2ms10096kbC++145.4kb2024-11-04 21:58:192024-11-04 21:58:20

Judging History

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

  • [2024-11-04 21:58:20]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:10096kb
  • [2024-11-04 21:58:19]
  • 提交

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 = 4e-11;
int n, m, a[N];
ll s[N];
pair<ldb, int> f[N];

bool check(ldb x) {
	static struct { 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) -> ldb {
		return f[l].fir + sqrtl((r - l) * (s[r] - s[l])) - x;
	};
//	cout << s[1] << endl;
	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 = val(Q[head].opt, i);
		while (head <= tail && val(Q[tail].opt, Q[tail].l) > 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;
			if (val(opt, r) > val(i, r)) {
					while (l <= r) {
						int mid = (l + r) >> 1;
						if (val(opt, mid) > 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};
	}
//	for (int i = 1; i <= n; i ++)
//		cout << f[i].fir << ' ' << f[i].sec << endl;
	return f[n].sec <= m;
}

void slv() {
	Read(n, m);
	for (int i = 1; i <= n; i ++) Read(a[i]);
	sort(a + 1, a + n + 1);
	partial_sum(a + 1, a + n + 1, s + 1);
//	check(- 0.035697), exit(0);
	ldb l = - 5e10, r = 0;
	while (fabsl(r - l) > eps) {
		ldb mid = (l + r) / 2;
		if (check(mid)) l = mid;
		else r = mid;
	}
//	cout << l << ' ' << f[n].fir << ' ' << f[n].sec << endl
	assert(f[n].sec<=m);
	check(l), printf("%.9Lf\n", f[n].fir + f[n].sec * l);
	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: 2ms
memory: 10044kb

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

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: 2ms
memory: 10096kb

input:

1 1
1

output:

1.000000000

result:

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

Test #4:

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

input:

1 1
100000

output:

316.227766017

result:

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

Test #5:

score: -100
Runtime Error

input:

7 1
10 47 53 9 83 33 15

output:


result: