답안 #1097199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097199 2024-10-06T12:02:07 Z crafticat Feast (NOI19_feast) C++17
49 / 100
1000 ms 26948 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, ll>;
#define ckmax(a,b) a= max(a,b)

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

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

    for (ll i = 1; i <= arr.size(); ++i) {
        dp[i][0] = {0,0};
        for (ll l = 0; l < 2; ++l) {
            ckmax(dp[i][l], max(max(dp[i - 1][1], dp[i - 1][0]) - pa, dp[i - 1][1]));
        }

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

    return max(dp[arr.size()][0], dp[arr.size()][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:46:9: warning: unused variable 'iter' [-Wunused-variable]
   46 |     int iter = 0;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 923 ms 26196 KB Output is correct
2 Correct 950 ms 26352 KB Output is correct
3 Execution timed out 1004 ms 26948 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 917 ms 24520 KB Output is correct
2 Correct 962 ms 25056 KB Output is correct
3 Correct 898 ms 24608 KB Output is correct
4 Correct 945 ms 24880 KB Output is correct
5 Correct 939 ms 26076 KB Output is correct
6 Correct 916 ms 24456 KB Output is correct
7 Correct 968 ms 25108 KB Output is correct
8 Correct 993 ms 26712 KB Output is correct
9 Correct 953 ms 25996 KB Output is correct
10 Correct 919 ms 24952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1012 ms 26740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 432 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 432 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 5 ms 604 KB Output is correct
22 Correct 5 ms 348 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 600 KB Output is correct
28 Correct 5 ms 608 KB Output is correct
29 Correct 5 ms 604 KB Output is correct
30 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 923 ms 26196 KB Output is correct
2 Correct 950 ms 26352 KB Output is correct
3 Execution timed out 1004 ms 26948 KB Time limit exceeded
4 Halted 0 ms 0 KB -