Submission #309943

#TimeUsernameProblemLanguageResultExecution timeMemory
309943phathnv새로운 문제 (COCI19_akvizna)C++11
130 / 130
463 ms3572 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair typedef long long ll; typedef pair<int, int> ii; struct line{ double a, b; int cnt; line(double _a = 0, double _b = 0, int _cnt = 0){ a = _a; b = _b; cnt = _cnt; } }; struct convexHull{ vector <line> d; int ptr; void reset(){ d.clear(); ptr = 0; } double calcY(const line &l, ll x){ return l.a * x + l.b; } bool bad(const line &l1, const line &l2, const line &l3){ return (l2.a - l3.a) * (l2.b - l1.b) >= (l1.a - l2.a) * (l3.b - l2.b); } void add(const line &newLine){ while (d.size() > 1){ if (bad(d[d.size() - 2], d[d.size() - 1], newLine)) d.pop_back(); else break; } d.push_back(newLine); } double getMax(double x){ assert(!d.empty()); ptr = min(ptr, (int) d.size() - 1); while (ptr < (int) d.size() - 1) if (calcY(d[ptr], x) <= calcY(d[ptr + 1], x)) ptr++; else break; return calcY(d[ptr], x); } int getCnt(double x){ assert(!d.empty()); ptr = min(ptr, (int) d.size() - 1); while (ptr < (int) d.size() - 1) if (calcY(d[ptr], x) <= calcY(d[ptr + 1], x)) ptr++; else break; return d[ptr].cnt; } } cvh; int n, k; void readInput(){ cin >> n >> k; } int calcCnt(double cost){ cvh.reset(); double val = 0; int cnt = 0; for(int i = 1; i <= n; i++){ cvh.add(line(val, -(i - 1), cnt)); val = cvh.getMax(i) / i + 1 - cost; cnt = cvh.getCnt(i) + 1; } return cnt; } double calcVal(double cost){ cvh.reset(); double val = 0; int cnt = 0; for(int i = 1; i <= n; i++){ cvh.add(line(val, -(i - 1), cnt)); val = cvh.getMax(i) / i + 1 - cost; cnt = cvh.getCnt(i) + 1; } return val; } void solve(){ double l = 0, r = 1, best = -1; for(int t = 1; t <= 200; t++){ double mid = (l + r) / 2.0; if (calcCnt(mid) <= k){ best = mid; r = mid; } else { l = mid; } } calcCnt(best); cout << fixed << setprecision(20) << calcVal(best) + best * k; } int main(){ readInput(); solve(); return 0; }
#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...