답안 #144089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144089 2019-08-16T02:25:28 Z ChrisT Akvizna (COCI19_akvizna) C++17
130 / 130
66 ms 3576 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) x.begin(),x.end()
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define m first
#define b second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<double,double> line;
char _;
template <typename t> void scan (t& x) {do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0);}
template <typename t, typename ...r> void scan (t& x, r&... xs) {scan(x); scan(xs...);}
const int MN = 1e5+2, MOD = 1e9+7;
double dp[MN];
int cnt[MN], which[MN], n;
line lines[MN];
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() {
    int K;
    scan(n,K);

    double low = 0, high = 20, mid;
    while (high-low >= 1e-12) {
        mid = (high+low)/2;
        solve(mid);
        if (cnt[n] <= K) high = mid;
        else low = mid;
    }
    solve(high);
    printf ("%.9f\n",dp[n] + cnt[n] * high);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 4 ms 552 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3264 KB Output is correct
2 Correct 60 ms 3372 KB Output is correct
3 Correct 60 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 3320 KB Output is correct
2 Correct 63 ms 3432 KB Output is correct
3 Correct 63 ms 3372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3320 KB Output is correct
2 Correct 63 ms 3576 KB Output is correct
3 Correct 64 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 3320 KB Output is correct
2 Correct 61 ms 3320 KB Output is correct
3 Correct 62 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 3320 KB Output is correct
2 Correct 63 ms 3448 KB Output is correct
3 Correct 62 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 3448 KB Output is correct
2 Correct 60 ms 3448 KB Output is correct
3 Correct 64 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 3416 KB Output is correct
2 Correct 58 ms 3192 KB Output is correct
3 Correct 61 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 3192 KB Output is correct
2 Correct 63 ms 3448 KB Output is correct
3 Correct 61 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 3448 KB Output is correct
2 Correct 61 ms 3416 KB Output is correct
3 Correct 65 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 3576 KB Output is correct
2 Correct 61 ms 3344 KB Output is correct
3 Correct 64 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 3448 KB Output is correct
2 Correct 62 ms 3448 KB Output is correct
3 Correct 66 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 3448 KB Output is correct
2 Correct 63 ms 3532 KB Output is correct
3 Correct 65 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 3576 KB Output is correct
2 Correct 63 ms 3548 KB Output is correct
3 Correct 65 ms 3452 KB Output is correct