답안 #154485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154485 2019-09-22T05:29:43 Z srvlt K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1000 ms 760 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse2,avx")
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 3, inf = 1e18, bound = 1e12;
const db eps = 1e-7;
int n, k, a[N], val[N], p[N];
db dp[N];

int calc(db x) {
    for (int i = 0; i <= n; i++) {
        dp[i] = inf;
        p[i] = val[i] = 0;
    }
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        int mx = 0;
        for (int j = i; j >= 1; j--) {
            mx = max(mx, a[j]);
            db tmp = dp[j - 1] + mx + x;
            if ((dp[i] > tmp) || (dp[i] > tmp - eps && p[i] > p[j - 1] + 1)) {
                dp[i] = tmp;
                p[i] = p[j - 1] + 1;
                val[i] = val[j - 1] + mx;
            }
        }
    }
    return p[n];
}

void solve(int tc) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    db l = -bound - eps, r = 0 + eps;
    while (l < r - eps) {
        db mid = (l + r) * (db)0.5;
        if (calc(mid) <= k) {
            r = mid;
        }   else {
            l = mid;
        }
    }
    cout << val[n];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 248 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1042 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -