QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#543858 | #8524. Weather Forecast | HTensor | WA | 0ms | 3948kb | C++17 | 2.2kb | 2024-09-01 22:16:44 | 2024-09-01 22:16:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
using db = long double;
class BIT {
public:
vector<int> val;
BIT() { }
BIT(int n) { val.resize(n + 1); }
void clear() {
fill(val.begin(), val.end(), -1);
}
int lowbit(int x) { return x & -x; }
void add(int u, int x) {
for(int i = u; i < (int)val.size(); i += lowbit(i)) val[i] = max(x, val[i]);
}
int query(int u) {
int ans = -1; for(int i = u; i; i -= lowbit(i)) ans = max(ans, val[i]); return ans;
}
};
// results start with 1
void discretize(vector<db>& a) {
vector<db> b(a);
sort(b.begin() + 1, b.end());
b.erase(unique(b.begin() + 1, b.end()), b.end());
for(int i = 1; i < (int)a.size(); i++)
a[i] = lower_bound(b.begin() + 1, b.end(), a[i]) - b.begin();
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> s(n + 1);
for (int i = 1; i <= n; i++) {
s[i] = s[i - 1] + a[i];
}
auto check = [&](db m) {
vector<db> v(n + 2);
for (int i = 1; i <= n; i++) {
v[i] = s[i] - i * m;
// cerr << v[i] << " \n"[i == n];
}
discretize(v);
BIT bit(n + 1);
bit.add(v[n + 1], 0);
vector<int> dp(n + 1);
for (int i = 1; i <= n; i++) {
dp[i] = bit.query(v[i] - 1) + 1;
// cerr << i << ": " << v[i] << " " << bit.query(v[i] - 1) << " " << dp[i] << "\n";
bit.add(v[i], dp[i]);
}
// for (int i = 1; i <= n; i++) {
// cerr << dp[i] << " \n"[i == n];
// }
return dp[n] >= k;
};
// check(1.7);
db lo = 0, hi = 1000;
while (hi - lo > 1e-9) {
db m = (lo + hi) / 2;
if (check(m)) {
lo = m;
} else {
hi = m;
}
}
cout << fixed << setprecision(10) << (lo + hi) / 2 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
input:
7 3 1 3 1 2 2 2 1
output:
1.6666666666
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3948kb
input:
1 1 1
output:
0.9999999997
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
2 1 2 1
output:
1.4999999999
result:
ok found '1.50000', expected '1.50000', error '0.00000'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3776kb
input:
3 2 2 4 4
output:
4.0000000004
result:
wrong answer 1st numbers differ - expected: '3.00000', found: '4.00000', error = '1.00000'