QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752202 | #9540. Double 11 | hos_lyric | WA | 0ms | 4080kb | C++14 | 3.7kb | 2024-11-15 22:54:41 | 2024-11-15 22:54:43 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
Int counter=0;
template <class T> struct MonotoneMinDP {
int n;
vector<T> ts;
vector<int> par;
vector<pair<int, int>> que;
template <class Cost> void run(int n_, Cost cost) {
auto get = [&](int l, int r) -> T {
// ++counter;assert(0<=l);assert(l<r);assert(r<=n);
return ts[l] + cost(l, r);
};
n = n_;
ts.resize(n + 1);
ts[0] = T();
par.resize(n + 1);
for (int i = 0; i <= n; ++i) par[i] = -1;
que.resize(n + 1);
// from que[k].first to [que[k].second, que[k + 1].second)
int head = 0, tail = 1;
que[0] = make_pair(0, 1);
for (int i = 1; i <= n; ++i) {
for (; head + 1 < tail && que[head + 1].second <= i; ++head) {}
ts[i] = get(par[i] = que[head].first, i);
for (int rr = n + 1; ; --tail) {
if (head == tail) {
que[tail++] = make_pair(i, i + 1);
break;
}
const int l = que[tail - 1].first, r = que[tail - 1].second;
if (i >= r || get(l, r) < get(i, r)) {
int lo = max(i + 1, r), hi = rr;
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
((get(l, mid) < get(i, mid)) ? lo : hi) = mid;
}
if (hi <= n) que[tail++] = make_pair(i, hi);
break;
} else {
rr = r;
}
}
}
}
T all() const {
return ts[n];
}
int countSteps() const {
int c = 0;
for (int i = n; i; i = par[i]) ++c;
return c;
}
};
using Double = long double;
int N, M;
vector<Int> S;
int main() {
for (; ~scanf("%d%d", &N, &M); ) {
S.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%lld", &S[i]);
}
sort(S.begin(), S.end());
vector<Int> SSum(N + 1, 0);
for (int i = 0; i < N; ++i) {
SSum[i + 1] = SSum[i] + S[i];
}
MonotoneMinDP<Double> f;
auto calc = [&](const Double pena) -> void {
f.run(N, [&](int l, int r) -> Double {
return sqrt((Double)((r - l) * (SSum[r] - SSum[l]))) + pena;
});
};
// cost <= sqrt(N SSum[N]) <= (2*10^5) * sqrt(10^5)
Double lo = -100, hi = +1e9L;
for (int iter = 0; iter < 60; ++iter) {
const Double mid = (lo + hi) / 2;
calc(mid);
((f.countSteps() >= M) ? lo : hi) = mid;
}
cerr<<"counter = "<<counter<<endl;
calc(lo);
const Double ans = f.all() - f.countSteps() * lo;
printf("%.20Lf\n", ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4080kb
input:
4 2 1 2 3 4
output:
6.19114712955711948405
result:
ok found '6.191147130', expected '6.191147130', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
10 3 1 2 3 4 5 6 7 8 9 10
output:
22.59162536651412858668
result:
ok found '22.591625367', expected '22.591625367', error '0.000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
1 1 1
output:
1.00000000000000000000
result:
ok found '1.000000000', expected '1.000000000', error '0.000000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 1 100000
output:
316.22776601684745401144
result:
ok found '316.227766017', expected '316.227766017', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
7 1 10 47 53 9 83 33 15
output:
41.83300132671138271689
result:
ok found '41.833001327', expected '41.833001327', error '0.000000000'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 4080kb
input:
8 5 138 1702 119 1931 418 1170 840 1794
output:
234.08141126126672543206
result:
wrong answer 1st numbers differ - expected: '233.9016546', found: '234.0814113', error = '0.0007685'