Submission #254201

#TimeUsernameProblemLanguageResultExecution timeMemory
254201NONAME새로운 문제 (COCI19_akvizna)C++14
130 / 130
70 ms3584 KiB
#include <bits/stdc++.h> #define m first #define b second #define dbg(x) cerr << #x << " = " << x << "\n" #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie() using namespace std; using ll = long long; using ld = long double; typedef pair <double, double> line; const int N = int(2e5) + 500; const int base = int(1e9) + 7; double dp[N]; int n, k; int cnt[N], which[N]; line lines[N]; double intersect(line f, line s) { return (f.m == s.m) ? 1e18 : (f.b - s.b) / (s.m - f.m); } double val(line a, double x) { return (a.m * x + a.b); } void solve(double cost) { int l = 0, r = 0; dp[0] = cnt[0] = 0; for (int i = 1; i <= n; ++i) { line nline = {dp[i - 1], -i}; while (r - l > 1 && intersect(nline, lines[r - 1]) < intersect(lines[r - 1], lines[r - 2])) --r; which[r] = i - 1; lines[r++] = nline; while (r - l > 1 && val(lines[l], i) <= val(lines[l + 1], i)) ++l; dp[i] = (val(lines[l], i) + i + 1) / i - cost; cnt[i] = cnt[which[l]] + 1; } } int main() { fast_io; cin >> n >> k; double low = 0, high = 20; while (high - low >= 1e-12) { double md = (low + high) / 2; solve(md); if (cnt[n] <= k) high = md; else low = md; } solve(high); cout.precision(20); cout << fixed; cout << dp[n] + cnt[n] * high << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...