답안 #389980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389980 2021-04-15T03:05:10 Z smax Feast (NOI19_feast) C++17
100 / 100
353 ms 7680 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; i++)
        cin >> a[i];

    auto solve = [&] (long long c) -> pair<bool, long long> {
        vector<long long> pref(n + 1);
        for (int i=0; i<n; i++)
            pref[i+1] = a[i] + pref[i];
        vector<long long> dp(n + 1);
        vector<int> cnt(n + 1);
        dp[0] = 0;
        int mx = 0;
        for (int i=0; i<n; i++) {
            dp[i+1] = dp[i];
            cnt[i+1] = cnt[i];
            if (dp[mx] + pref[i+1] - pref[mx] - c > dp[i]) {
                dp[i+1] = dp[mx] + pref[i+1] - pref[mx] - c;
                cnt[i+1] = cnt[mx] + 1;
            }
            if (dp[i+1] - pref[i+1] > dp[mx] - pref[mx])
                mx = i + 1;
        }
        return {cnt[n] <= k, dp[n] + c * cnt[n]};
    };

    long long l = 0, r = 1e18;
    while (l < r) {
        long long m = (l + r) / 2;
        if (solve(m).first)
            r = m;
        else
            l = m + 1;
    }
    cout << solve(l).second << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 7304 KB Output is correct
2 Correct 319 ms 7316 KB Output is correct
3 Correct 299 ms 7680 KB Output is correct
4 Correct 297 ms 7320 KB Output is correct
5 Correct 293 ms 7364 KB Output is correct
6 Correct 300 ms 7208 KB Output is correct
7 Correct 317 ms 7264 KB Output is correct
8 Correct 324 ms 7496 KB Output is correct
9 Correct 288 ms 7260 KB Output is correct
10 Correct 301 ms 7432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 7248 KB Output is correct
2 Correct 285 ms 7388 KB Output is correct
3 Correct 276 ms 7284 KB Output is correct
4 Correct 284 ms 7296 KB Output is correct
5 Correct 332 ms 7248 KB Output is correct
6 Correct 285 ms 7252 KB Output is correct
7 Correct 275 ms 7428 KB Output is correct
8 Correct 323 ms 7444 KB Output is correct
9 Correct 292 ms 7212 KB Output is correct
10 Correct 281 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 7376 KB Output is correct
2 Correct 284 ms 7276 KB Output is correct
3 Correct 286 ms 7316 KB Output is correct
4 Correct 287 ms 7280 KB Output is correct
5 Correct 297 ms 7356 KB Output is correct
6 Correct 298 ms 7344 KB Output is correct
7 Correct 277 ms 7360 KB Output is correct
8 Correct 291 ms 7604 KB Output is correct
9 Correct 288 ms 7432 KB Output is correct
10 Correct 301 ms 7412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 7304 KB Output is correct
2 Correct 319 ms 7316 KB Output is correct
3 Correct 299 ms 7680 KB Output is correct
4 Correct 297 ms 7320 KB Output is correct
5 Correct 293 ms 7364 KB Output is correct
6 Correct 300 ms 7208 KB Output is correct
7 Correct 317 ms 7264 KB Output is correct
8 Correct 324 ms 7496 KB Output is correct
9 Correct 288 ms 7260 KB Output is correct
10 Correct 301 ms 7432 KB Output is correct
11 Correct 266 ms 7248 KB Output is correct
12 Correct 285 ms 7388 KB Output is correct
13 Correct 276 ms 7284 KB Output is correct
14 Correct 284 ms 7296 KB Output is correct
15 Correct 332 ms 7248 KB Output is correct
16 Correct 285 ms 7252 KB Output is correct
17 Correct 275 ms 7428 KB Output is correct
18 Correct 323 ms 7444 KB Output is correct
19 Correct 292 ms 7212 KB Output is correct
20 Correct 281 ms 7404 KB Output is correct
21 Correct 279 ms 7376 KB Output is correct
22 Correct 284 ms 7276 KB Output is correct
23 Correct 286 ms 7316 KB Output is correct
24 Correct 287 ms 7280 KB Output is correct
25 Correct 297 ms 7356 KB Output is correct
26 Correct 298 ms 7344 KB Output is correct
27 Correct 277 ms 7360 KB Output is correct
28 Correct 291 ms 7604 KB Output is correct
29 Correct 288 ms 7432 KB Output is correct
30 Correct 301 ms 7412 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 332 KB Output is correct
53 Correct 2 ms 364 KB Output is correct
54 Correct 2 ms 332 KB Output is correct
55 Correct 2 ms 336 KB Output is correct
56 Correct 2 ms 332 KB Output is correct
57 Correct 2 ms 332 KB Output is correct
58 Correct 2 ms 332 KB Output is correct
59 Correct 2 ms 332 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 353 ms 7340 KB Output is correct
62 Correct 343 ms 7428 KB Output is correct
63 Correct 314 ms 7232 KB Output is correct
64 Correct 326 ms 7348 KB Output is correct
65 Correct 319 ms 7396 KB Output is correct
66 Correct 313 ms 7500 KB Output is correct
67 Correct 310 ms 7252 KB Output is correct
68 Correct 299 ms 7320 KB Output is correct
69 Correct 293 ms 7216 KB Output is correct
70 Correct 279 ms 7200 KB Output is correct