답안 #666457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666457 2022-11-28T16:29:59 Z hoanghq2004 Feast (NOI19_feast) C++14
100 / 100
120 ms 10524 KB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 3e5 + 10;

int n, k;
long long s[N];
pair <long long, int> f[N];

int calc(long long C) {
    pair <long long, int> opt = {0, 0};
    for (int i = 1; i <= n; ++i) {
        f[i].first = opt.first + s[i] - C;
        f[i].second = opt.second - 1;
        if (f[i] < f[i - 1]) f[i] = f[i - 1];
        if (make_pair(f[i].first - s[i], f[i].second) > opt)
            opt = make_pair(f[i].first - s[i], f[i].second);
    }
    return - f[n].second;
}

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
        s[i] += s[i - 1];
    }
    if (calc(0) <= k) {
        cout << f[n].first << '\n';
        exit(0);
    }
    long long L = 0, R = 1e14;
    while (L < R) {
        long long mid = L + R >> 1;
        if (calc(mid) <= k) R = mid;
        else L = mid + 1;
    }
    calc(L);
    cout << f[n].first + 1LL * k * L << '\n';
}

Compilation message

feast.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
feast.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
feast.cpp: In function 'int main()':
feast.cpp:44:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         long long mid = L + R >> 1;
      |                         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 9928 KB Output is correct
2 Correct 30 ms 10092 KB Output is correct
3 Correct 31 ms 10164 KB Output is correct
4 Correct 30 ms 10148 KB Output is correct
5 Correct 29 ms 10060 KB Output is correct
6 Correct 30 ms 9860 KB Output is correct
7 Correct 39 ms 9840 KB Output is correct
8 Correct 32 ms 10184 KB Output is correct
9 Correct 29 ms 9940 KB Output is correct
10 Correct 29 ms 10048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 8272 KB Output is correct
2 Correct 51 ms 8484 KB Output is correct
3 Correct 63 ms 8280 KB Output is correct
4 Correct 20 ms 8268 KB Output is correct
5 Correct 61 ms 9900 KB Output is correct
6 Correct 49 ms 8284 KB Output is correct
7 Correct 24 ms 8400 KB Output is correct
8 Correct 55 ms 10156 KB Output is correct
9 Correct 58 ms 9892 KB Output is correct
10 Correct 22 ms 8396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 10272 KB Output is correct
2 Correct 82 ms 10148 KB Output is correct
3 Correct 84 ms 10228 KB Output is correct
4 Correct 84 ms 10156 KB Output is correct
5 Correct 96 ms 10184 KB Output is correct
6 Correct 83 ms 10336 KB Output is correct
7 Correct 80 ms 10248 KB Output is correct
8 Correct 79 ms 10268 KB Output is correct
9 Correct 89 ms 10524 KB Output is correct
10 Correct 81 ms 10372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 9928 KB Output is correct
2 Correct 30 ms 10092 KB Output is correct
3 Correct 31 ms 10164 KB Output is correct
4 Correct 30 ms 10148 KB Output is correct
5 Correct 29 ms 10060 KB Output is correct
6 Correct 30 ms 9860 KB Output is correct
7 Correct 39 ms 9840 KB Output is correct
8 Correct 32 ms 10184 KB Output is correct
9 Correct 29 ms 9940 KB Output is correct
10 Correct 29 ms 10048 KB Output is correct
11 Correct 53 ms 8272 KB Output is correct
12 Correct 51 ms 8484 KB Output is correct
13 Correct 63 ms 8280 KB Output is correct
14 Correct 20 ms 8268 KB Output is correct
15 Correct 61 ms 9900 KB Output is correct
16 Correct 49 ms 8284 KB Output is correct
17 Correct 24 ms 8400 KB Output is correct
18 Correct 55 ms 10156 KB Output is correct
19 Correct 58 ms 9892 KB Output is correct
20 Correct 22 ms 8396 KB Output is correct
21 Correct 81 ms 10272 KB Output is correct
22 Correct 82 ms 10148 KB Output is correct
23 Correct 84 ms 10228 KB Output is correct
24 Correct 84 ms 10156 KB Output is correct
25 Correct 96 ms 10184 KB Output is correct
26 Correct 83 ms 10336 KB Output is correct
27 Correct 80 ms 10248 KB Output is correct
28 Correct 79 ms 10268 KB Output is correct
29 Correct 89 ms 10524 KB Output is correct
30 Correct 81 ms 10372 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 324 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 328 KB Output is correct
46 Correct 1 ms 324 KB Output is correct
47 Correct 1 ms 328 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 360 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 115 ms 10056 KB Output is correct
62 Correct 35 ms 10292 KB Output is correct
63 Correct 98 ms 10136 KB Output is correct
64 Correct 120 ms 10464 KB Output is correct
65 Correct 116 ms 10332 KB Output is correct
66 Correct 119 ms 10188 KB Output is correct
67 Correct 117 ms 10132 KB Output is correct
68 Correct 95 ms 10340 KB Output is correct
69 Correct 83 ms 10152 KB Output is correct
70 Correct 81 ms 10000 KB Output is correct