답안 #1101997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101997 2024-10-17T09:14:01 Z Zero_OP Feast (NOI19_feast) C++14
100 / 100
128 ms 13920 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int MAX = 3e5 + 5;
pair<ll, int> dp[2][MAX];

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

    if(fopen("task.inp", "r")){
        freopen("task.inp", "r", stdin);
        freopen("task.out", "w", stdout);
    }


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

    auto f = [&](ll lambda) -> pair<ll, int> {
        dp[0][1] = {0, 0};
        dp[1][1] = {a[1] - lambda, 1};
        for(int i = 2; i <= n; ++i){
            dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]);
            dp[1][i] = max(make_pair(dp[0][i - 1].first + a[i] - lambda, dp[0][i - 1].second + 1),
                           make_pair(dp[1][i - 1].first + a[i], dp[1][i - 1].second));
        }

        return max(dp[0][n], dp[1][n]);
    };

    ll l = 0, r = 1e18, lambda_opt = 0;
    while(l <= r){
        ll mid = l + r >> 1;
        pair<ll, int> eval = f(mid);
        if(eval.second >= k) lambda_opt = mid, l = mid + 1;
        else r = mid - 1;
    }

    ll ret = f(lambda_opt).first + lambda_opt * k;
    cout << ret << '\n';

    return 0;
}

Compilation message

feast.cpp: In function 'int main()':
feast.cpp:41:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |         ll mid = l + r >> 1;
      |                  ~~^~~
feast.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen("task.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 10824 KB Output is correct
2 Correct 60 ms 13788 KB Output is correct
3 Correct 60 ms 13908 KB Output is correct
4 Correct 58 ms 13644 KB Output is correct
5 Correct 60 ms 13644 KB Output is correct
6 Correct 57 ms 13652 KB Output is correct
7 Correct 57 ms 13396 KB Output is correct
8 Correct 61 ms 13648 KB Output is correct
9 Correct 62 ms 13652 KB Output is correct
10 Correct 57 ms 13644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 11000 KB Output is correct
2 Correct 49 ms 10872 KB Output is correct
3 Correct 51 ms 10832 KB Output is correct
4 Correct 48 ms 10832 KB Output is correct
5 Correct 60 ms 13652 KB Output is correct
6 Correct 50 ms 12024 KB Output is correct
7 Correct 52 ms 12108 KB Output is correct
8 Correct 59 ms 13652 KB Output is correct
9 Correct 57 ms 13500 KB Output is correct
10 Correct 50 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 10832 KB Output is correct
2 Correct 85 ms 10832 KB Output is correct
3 Correct 83 ms 10832 KB Output is correct
4 Correct 80 ms 10832 KB Output is correct
5 Correct 82 ms 10824 KB Output is correct
6 Correct 82 ms 10844 KB Output is correct
7 Correct 83 ms 10832 KB Output is correct
8 Correct 80 ms 10824 KB Output is correct
9 Correct 82 ms 10832 KB Output is correct
10 Correct 87 ms 10856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2624 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2624 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 1 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2552 KB Output is correct
14 Correct 1 ms 2388 KB Output is correct
15 Correct 1 ms 2388 KB Output is correct
16 Correct 1 ms 2776 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
19 Correct 1 ms 2388 KB Output is correct
20 Correct 1 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2624 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 1 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 1 ms 2552 KB Output is correct
14 Correct 1 ms 2388 KB Output is correct
15 Correct 1 ms 2388 KB Output is correct
16 Correct 1 ms 2776 KB Output is correct
17 Correct 1 ms 2388 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
19 Correct 1 ms 2388 KB Output is correct
20 Correct 1 ms 2388 KB Output is correct
21 Correct 2 ms 2388 KB Output is correct
22 Correct 1 ms 2388 KB Output is correct
23 Correct 1 ms 2388 KB Output is correct
24 Correct 2 ms 2388 KB Output is correct
25 Correct 1 ms 2388 KB Output is correct
26 Correct 2 ms 2388 KB Output is correct
27 Correct 2 ms 2388 KB Output is correct
28 Correct 2 ms 2388 KB Output is correct
29 Correct 2 ms 2556 KB Output is correct
30 Correct 1 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 10824 KB Output is correct
2 Correct 60 ms 13788 KB Output is correct
3 Correct 60 ms 13908 KB Output is correct
4 Correct 58 ms 13644 KB Output is correct
5 Correct 60 ms 13644 KB Output is correct
6 Correct 57 ms 13652 KB Output is correct
7 Correct 57 ms 13396 KB Output is correct
8 Correct 61 ms 13648 KB Output is correct
9 Correct 62 ms 13652 KB Output is correct
10 Correct 57 ms 13644 KB Output is correct
11 Correct 47 ms 11000 KB Output is correct
12 Correct 49 ms 10872 KB Output is correct
13 Correct 51 ms 10832 KB Output is correct
14 Correct 48 ms 10832 KB Output is correct
15 Correct 60 ms 13652 KB Output is correct
16 Correct 50 ms 12024 KB Output is correct
17 Correct 52 ms 12108 KB Output is correct
18 Correct 59 ms 13652 KB Output is correct
19 Correct 57 ms 13500 KB Output is correct
20 Correct 50 ms 12116 KB Output is correct
21 Correct 81 ms 10832 KB Output is correct
22 Correct 85 ms 10832 KB Output is correct
23 Correct 83 ms 10832 KB Output is correct
24 Correct 80 ms 10832 KB Output is correct
25 Correct 82 ms 10824 KB Output is correct
26 Correct 82 ms 10844 KB Output is correct
27 Correct 83 ms 10832 KB Output is correct
28 Correct 80 ms 10824 KB Output is correct
29 Correct 82 ms 10832 KB Output is correct
30 Correct 87 ms 10856 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2552 KB Output is correct
34 Correct 1 ms 2388 KB Output is correct
35 Correct 1 ms 2624 KB Output is correct
36 Correct 1 ms 2388 KB Output is correct
37 Correct 1 ms 2388 KB Output is correct
38 Correct 1 ms 2388 KB Output is correct
39 Correct 1 ms 2388 KB Output is correct
40 Correct 1 ms 2388 KB Output is correct
41 Correct 1 ms 2388 KB Output is correct
42 Correct 1 ms 2388 KB Output is correct
43 Correct 1 ms 2552 KB Output is correct
44 Correct 1 ms 2388 KB Output is correct
45 Correct 1 ms 2388 KB Output is correct
46 Correct 1 ms 2776 KB Output is correct
47 Correct 1 ms 2388 KB Output is correct
48 Correct 1 ms 2388 KB Output is correct
49 Correct 1 ms 2388 KB Output is correct
50 Correct 1 ms 2388 KB Output is correct
51 Correct 2 ms 2388 KB Output is correct
52 Correct 1 ms 2388 KB Output is correct
53 Correct 1 ms 2388 KB Output is correct
54 Correct 2 ms 2388 KB Output is correct
55 Correct 1 ms 2388 KB Output is correct
56 Correct 2 ms 2388 KB Output is correct
57 Correct 2 ms 2388 KB Output is correct
58 Correct 2 ms 2388 KB Output is correct
59 Correct 2 ms 2556 KB Output is correct
60 Correct 1 ms 2388 KB Output is correct
61 Correct 120 ms 13644 KB Output is correct
62 Correct 113 ms 13900 KB Output is correct
63 Correct 99 ms 13652 KB Output is correct
64 Correct 116 ms 13812 KB Output is correct
65 Correct 128 ms 13900 KB Output is correct
66 Correct 120 ms 13920 KB Output is correct
67 Correct 121 ms 13780 KB Output is correct
68 Correct 88 ms 13900 KB Output is correct
69 Correct 85 ms 13752 KB Output is correct
70 Correct 83 ms 13644 KB Output is correct