Submission #246565

# Submission time Handle Problem Language Result Execution time Memory
246565 2020-07-09T15:26:54 Z BartolM Akvizna (COCI19_akvizna) C++17
130 / 130
257 ms 4848 KB
#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

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 time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 11 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 11 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 13 ms 512 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 512 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 13 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 512 KB Output is correct
2 Correct 11 ms 512 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 4844 KB Output is correct
2 Correct 235 ms 4716 KB Output is correct
3 Correct 231 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 4716 KB Output is correct
2 Correct 238 ms 4716 KB Output is correct
3 Correct 244 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 4716 KB Output is correct
2 Correct 244 ms 4716 KB Output is correct
3 Correct 251 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 4716 KB Output is correct
2 Correct 240 ms 4716 KB Output is correct
3 Correct 237 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 4588 KB Output is correct
2 Correct 243 ms 4716 KB Output is correct
3 Correct 239 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 4716 KB Output is correct
2 Correct 230 ms 4716 KB Output is correct
3 Correct 255 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 4716 KB Output is correct
2 Correct 227 ms 4588 KB Output is correct
3 Correct 237 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 4716 KB Output is correct
2 Correct 256 ms 4716 KB Output is correct
3 Correct 235 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 235 ms 4716 KB Output is correct
2 Correct 233 ms 4716 KB Output is correct
3 Correct 256 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 4716 KB Output is correct
2 Correct 231 ms 4716 KB Output is correct
3 Correct 253 ms 4720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 235 ms 4716 KB Output is correct
2 Correct 242 ms 4716 KB Output is correct
3 Correct 249 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 4716 KB Output is correct
2 Correct 243 ms 4848 KB Output is correct
3 Correct 257 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 235 ms 4716 KB Output is correct
2 Correct 246 ms 4716 KB Output is correct
3 Correct 250 ms 4716 KB Output is correct