QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702809 | #9540. Double 11 | ucup-team133# | WA | 1ms | 3936kb | C++23 | 3.6kb | 2024-11-02 16:37:01 | 2024-11-02 16:37:10 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
template <typename T, bool get_min = true>
std::pair<long long, T> golden_section_search(const std::function<T(long long)>& f, long long mini, long long maxi) {
assert(mini <= maxi);
long long a = mini - 1, x, b;
{
long long s = 1, t = 2;
while (t < maxi - mini + 2) std::swap(s += t, t);
x = a + t - s, b = a + t;
}
T fx = f(x), fy;
while (a + b != 2 * x) {
long long y = a + b - x;
fy = f(y);
if (maxi < y or (get_min ? fx < fy : fx > fy)) {
b = a;
a = y;
} else {
a = x;
x = y;
fx = fy;
}
}
return {x, fx};
}
template <typename T> std::vector<T> monge_shortest_path(int N, const std::function<T(int, int)>& f) {
std::vector<T> dp(N + 1, std::numeric_limits<T>::max() / 2);
std::vector<int> x(N + 1);
dp[0] = x[0] = 0, x[N] = N;
auto check = [&](int from, int to) {
if (from >= to) return;
T cost = f(from, to);
if (dp[from] + cost < dp[to]) {
dp[to] = dp[from] + cost;
x[to] = from;
}
};
auto solve = [&](auto&& self, int l, int r) -> void {
if (l >= r) return;
int m = (l + r) >> 1;
x[m] = x[l];
for (int i = x[l]; i <= x[r]; i++) check(i, m);
if (r - l > 1) self(self, l, m);
for (int i = l; i <= m; i++) check(i, r);
if (r - l > 1) self(self, m, r);
};
solve(solve, 0, N);
return dp;
}
template <typename T> T monge_d_edge_shortest_path(int N, int D, T upper, const std::function<T(int, int)>& f) {
assert(0 <= upper);
auto dp = [&](T x) -> T {
auto g = [&](int from, int to) -> T { return f(from, to) + x; };
T cost = monge_shortest_path<T>(N, g)[N];
return cost - 1LL * D * x;
};
T lb = -upper, ub = upper;
for (int _ = 0; _ < 200; _++) {
T low = (lb * 2 + ub) / 3, high = (lb + ub * 2) / 3;
T L = dp(low), R = dp(high);
if (L < R) {
lb = low;
} else {
ub = high;
}
}
return dp(ub);
}
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int n, m;
cin >> n >> m;
vector<int> s(n);
cin >> s;
ranges::sort(s);
vector<ll> sum(n + 1);
sum[0] = 0;
for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + s[i];
auto f = [&](int l, int r) -> long double { return sqrtl((sum[r] - sum[l]) * (r - l)); };
auto ans = monge_d_edge_shortest_path<long double>(n, m, 1e17, f);
cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3852kb
input:
4 2 1 2 3 4
output:
6.191147129557119
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.591625366514129
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1 1 1
output:
1.000000000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3936kb
input:
1 1 100000
output:
316.228515625000000
result:
wrong answer 1st numbers differ - expected: '316.2277660', found: '316.2285156', error = '0.0000024'