답안 #389978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389978 2021-04-15T03:02:14 Z smax Feast (NOI19_feast) C++17
100 / 100
351 ms 12744 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<__int128_t> 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 292 ms 12348 KB Output is correct
2 Correct 319 ms 12440 KB Output is correct
3 Correct 290 ms 12480 KB Output is correct
4 Correct 291 ms 12480 KB Output is correct
5 Correct 291 ms 12356 KB Output is correct
6 Correct 281 ms 12204 KB Output is correct
7 Correct 289 ms 12236 KB Output is correct
8 Correct 302 ms 12420 KB Output is correct
9 Correct 284 ms 12204 KB Output is correct
10 Correct 283 ms 12348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 256 ms 10620 KB Output is correct
2 Correct 269 ms 10820 KB Output is correct
3 Correct 273 ms 10572 KB Output is correct
4 Correct 284 ms 10668 KB Output is correct
5 Correct 283 ms 12188 KB Output is correct
6 Correct 262 ms 10524 KB Output is correct
7 Correct 276 ms 10824 KB Output is correct
8 Correct 292 ms 12516 KB Output is correct
9 Correct 281 ms 12104 KB Output is correct
10 Correct 274 ms 10736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 272 ms 12612 KB Output is correct
2 Correct 274 ms 12412 KB Output is correct
3 Correct 271 ms 12612 KB Output is correct
4 Correct 310 ms 12584 KB Output is correct
5 Correct 276 ms 12580 KB Output is correct
6 Correct 285 ms 12672 KB Output is correct
7 Correct 276 ms 12628 KB Output is correct
8 Correct 287 ms 12584 KB Output is correct
9 Correct 284 ms 12744 KB Output is correct
10 Correct 278 ms 12624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 1 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 204 KB Output is correct
3 Correct 1 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 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 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 312 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 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 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 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 312 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 412 KB Output is correct
26 Correct 2 ms 328 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 12348 KB Output is correct
2 Correct 319 ms 12440 KB Output is correct
3 Correct 290 ms 12480 KB Output is correct
4 Correct 291 ms 12480 KB Output is correct
5 Correct 291 ms 12356 KB Output is correct
6 Correct 281 ms 12204 KB Output is correct
7 Correct 289 ms 12236 KB Output is correct
8 Correct 302 ms 12420 KB Output is correct
9 Correct 284 ms 12204 KB Output is correct
10 Correct 283 ms 12348 KB Output is correct
11 Correct 256 ms 10620 KB Output is correct
12 Correct 269 ms 10820 KB Output is correct
13 Correct 273 ms 10572 KB Output is correct
14 Correct 284 ms 10668 KB Output is correct
15 Correct 283 ms 12188 KB Output is correct
16 Correct 262 ms 10524 KB Output is correct
17 Correct 276 ms 10824 KB Output is correct
18 Correct 292 ms 12516 KB Output is correct
19 Correct 281 ms 12104 KB Output is correct
20 Correct 274 ms 10736 KB Output is correct
21 Correct 272 ms 12612 KB Output is correct
22 Correct 274 ms 12412 KB Output is correct
23 Correct 271 ms 12612 KB Output is correct
24 Correct 310 ms 12584 KB Output is correct
25 Correct 276 ms 12580 KB Output is correct
26 Correct 285 ms 12672 KB Output is correct
27 Correct 276 ms 12628 KB Output is correct
28 Correct 287 ms 12584 KB Output is correct
29 Correct 284 ms 12744 KB Output is correct
30 Correct 278 ms 12624 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 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 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 332 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 312 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 2 ms 344 KB Output is correct
52 Correct 2 ms 332 KB Output is correct
53 Correct 3 ms 332 KB Output is correct
54 Correct 2 ms 332 KB Output is correct
55 Correct 2 ms 412 KB Output is correct
56 Correct 2 ms 328 KB Output is correct
57 Correct 2 ms 332 KB Output is correct
58 Correct 2 ms 332 KB Output is correct
59 Correct 3 ms 332 KB Output is correct
60 Correct 2 ms 332 KB Output is correct
61 Correct 337 ms 12400 KB Output is correct
62 Correct 351 ms 12740 KB Output is correct
63 Correct 283 ms 12404 KB Output is correct
64 Correct 331 ms 12664 KB Output is correct
65 Correct 322 ms 12660 KB Output is correct
66 Correct 326 ms 12612 KB Output is correct
67 Correct 312 ms 12408 KB Output is correct
68 Correct 281 ms 12656 KB Output is correct
69 Correct 272 ms 12412 KB Output is correct
70 Correct 276 ms 12356 KB Output is correct