답안 #1097208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097208 2024-10-06T12:13:33 Z crafticat Feast (NOI19_feast) C++17
100 / 100
477 ms 5816 KB
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"

using namespace std;
template<typename T>
using V = vector<T>;
using ll = long long;
using pi = pair<ll, int>;
#define ckmax(a,b) a = max(a,b)

inline std::pair<long long, int> operator-(const std::pair<long long, int>& p1, const std::pair<long long, int>& p2) {
    return {p1.first - p2.first, p1.second - p2.second};
}

pi solve(V<ll>&arr, ll k, ll p) {
    V<pi> dp(2,{-1e18,0});
    dp[0] = {0,0};
    pi pa = make_pair(p,-1);

    for (ll i = 1; i <= arr.size(); ++i) {
        auto newDp = dp;

        newDp[1] = {-1e18,0};
        newDp[0] = {0,0};
        for (ll l = 0; l < 2; ++l) {
            ckmax(newDp[l], max(max(dp[1], dp[0]) - pa, dp[1]));
        }

        ckmax(newDp[0], dp[0]);
        newDp[1].first += arr[i - 1];
        dp = newDp;
    }

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

int main() {
    ll n, k; cin >> n >> k;

    V<ll> arr(n);
    for (ll i = 0; i < n; ++i) {
        cin >> arr[i];
    }


    ll l = 0, r = 1e18;
    int iter = 0;
    while (r > l) {
        ll mid = l + (r - l + 1) / 2;
        if (solve(arr, k, mid).second >= k)
            l = mid;
        else
            r = mid - 1;
    }

    cout << solve(arr,k,l).first + l * k << "\n";
}

Compilation message

feast.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("O3")
      | 
feast.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("unroll-loops")
      | 
feast.cpp: In function 'pi solve(V<long long int>&, ll, ll)':
feast.cpp:23:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (ll i = 1; i <= arr.size(); ++i) {
      |                    ~~^~~~~~~~~~~~~
feast.cpp: In function 'int main()':
feast.cpp:50:9: warning: unused variable 'iter' [-Wunused-variable]
   50 |     int iter = 0;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 403 ms 2648 KB Output is correct
2 Correct 411 ms 2652 KB Output is correct
3 Correct 415 ms 2652 KB Output is correct
4 Correct 429 ms 2648 KB Output is correct
5 Correct 396 ms 2652 KB Output is correct
6 Correct 396 ms 2700 KB Output is correct
7 Correct 386 ms 2692 KB Output is correct
8 Correct 405 ms 2648 KB Output is correct
9 Correct 397 ms 2700 KB Output is correct
10 Correct 422 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 353 ms 2652 KB Output is correct
2 Correct 367 ms 2764 KB Output is correct
3 Correct 362 ms 2652 KB Output is correct
4 Correct 369 ms 3668 KB Output is correct
5 Correct 397 ms 5456 KB Output is correct
6 Correct 359 ms 3824 KB Output is correct
7 Correct 397 ms 3660 KB Output is correct
8 Correct 403 ms 5460 KB Output is correct
9 Correct 384 ms 5388 KB Output is correct
10 Correct 360 ms 3884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 436 ms 2648 KB Output is correct
2 Correct 428 ms 5696 KB Output is correct
3 Correct 428 ms 5716 KB Output is correct
4 Correct 414 ms 5532 KB Output is correct
5 Correct 427 ms 5664 KB Output is correct
6 Correct 435 ms 5548 KB Output is correct
7 Correct 434 ms 5716 KB Output is correct
8 Correct 437 ms 5712 KB Output is correct
9 Correct 430 ms 5772 KB Output is correct
10 Correct 418 ms 5556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 403 ms 2648 KB Output is correct
2 Correct 411 ms 2652 KB Output is correct
3 Correct 415 ms 2652 KB Output is correct
4 Correct 429 ms 2648 KB Output is correct
5 Correct 396 ms 2652 KB Output is correct
6 Correct 396 ms 2700 KB Output is correct
7 Correct 386 ms 2692 KB Output is correct
8 Correct 405 ms 2648 KB Output is correct
9 Correct 397 ms 2700 KB Output is correct
10 Correct 422 ms 2648 KB Output is correct
11 Correct 353 ms 2652 KB Output is correct
12 Correct 367 ms 2764 KB Output is correct
13 Correct 362 ms 2652 KB Output is correct
14 Correct 369 ms 3668 KB Output is correct
15 Correct 397 ms 5456 KB Output is correct
16 Correct 359 ms 3824 KB Output is correct
17 Correct 397 ms 3660 KB Output is correct
18 Correct 403 ms 5460 KB Output is correct
19 Correct 384 ms 5388 KB Output is correct
20 Correct 360 ms 3884 KB Output is correct
21 Correct 436 ms 2648 KB Output is correct
22 Correct 428 ms 5696 KB Output is correct
23 Correct 428 ms 5716 KB Output is correct
24 Correct 414 ms 5532 KB Output is correct
25 Correct 427 ms 5664 KB Output is correct
26 Correct 435 ms 5548 KB Output is correct
27 Correct 434 ms 5716 KB Output is correct
28 Correct 437 ms 5712 KB Output is correct
29 Correct 430 ms 5772 KB Output is correct
30 Correct 418 ms 5556 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 600 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 3 ms 344 KB Output is correct
52 Correct 3 ms 348 KB Output is correct
53 Correct 3 ms 348 KB Output is correct
54 Correct 3 ms 348 KB Output is correct
55 Correct 3 ms 348 KB Output is correct
56 Correct 4 ms 348 KB Output is correct
57 Correct 3 ms 348 KB Output is correct
58 Correct 3 ms 468 KB Output is correct
59 Correct 3 ms 348 KB Output is correct
60 Correct 3 ms 348 KB Output is correct
61 Correct 472 ms 5692 KB Output is correct
62 Correct 463 ms 5708 KB Output is correct
63 Correct 437 ms 5680 KB Output is correct
64 Correct 463 ms 5716 KB Output is correct
65 Correct 477 ms 5716 KB Output is correct
66 Correct 461 ms 5816 KB Output is correct
67 Correct 457 ms 5688 KB Output is correct
68 Correct 426 ms 5796 KB Output is correct
69 Correct 407 ms 5508 KB Output is correct
70 Correct 426 ms 5456 KB Output is correct