Submission #246565

#TimeUsernameProblemLanguageResultExecution timeMemory
246565BartolM새로운 문제 (COCI19_akvizna)C++17
130 / 130
257 ms4848 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> pip; typedef pair <double, double> pdd; typedef pair <pdd, int> ppi; typedef pair <double, int> pdi; const int INF=0x3f3f3f3f; const int N=100005; int n, k; vector <ppi> hull; int ind, cnt[N]; double dp[N], dp2[105][105]; double ccw(pdd a, pdd b, pdd c) { return a.X*(b.Y-c.Y)+b.X*(c.Y-a.Y)+c.X*(a.Y-b.Y); } double f(pdd pp, double x) { return pp.X*x+pp.Y; } void dodaj(ppi pp) { while (hull.size()>1 && ccw(hull[(int)hull.size()-2].X, hull.back().X, pp.X)>=0) hull.pop_back(); hull.pb(pp); ind=min(ind, (int)hull.size()-1); } pdi query(double x) { while (ind<(int)hull.size()-1 && f(hull[ind].X, x)<f(hull[ind+1].X, x)) ++ind; return mp(f(hull[ind].X, x), hull[ind].Y); } void solve(double lambda) { dp[0]=0; cnt[0]=0; ind=0; hull.clear(); hull.pb(mp(mp(1.0/(double)(n), 0), 0)); for (int i=1; i<=n; ++i) { pdi curr=query(i); curr.X-=lambda; curr.Y++; dp[i]=curr.X; cnt[i]=curr.Y; dodaj(mp(mp(1.0/(double)(n-i), curr.X-(double)i/(n-i)), curr.Y)); } } int main() { scanf("%d %d", &n, &k); // for (int i=1; i<=n; ++i) { // for (int j=1; j<=k; ++j) { // for (int l=0; l<i; ++l) { // dp2[i][j]=max(dp2[i][j], dp2[l][j-1]+(double)(i-l)/(double)(n-l)); // } // if (j>=2) printf("i: %d, j: %d, pada: %d\n", i, j, (dp2[i][j]-dp2[i][j-1])<=(dp2[i][j-1]-dp2[i][j-2])); // } // } // printf("%.10f\n", dp2[n][k]); double lo=0, hi=n, mid; int br=0; while (br<100) { mid=(lo+hi)/2; solve(mid); if (cnt[n]>k) lo=mid; else hi=mid; br++; } solve(lo); printf("%.10f\n", dp[n]+lo*k); return 0; }

Compilation message (stderr)

akvizna.cpp: In function 'int main()':
akvizna.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
#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...