답안 #1097185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097185 2024-10-06T11:51:38 Z crafticat Feast (NOI19_feast) C++17
0 / 100
1000 ms 26312 KB
#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)

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};

    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(dp[i - 1][1] - make_pair(p,-1), dp[i - 1][1]));
            if (l == 0) ckmax(dp[i][l], dp[i - 1][0]);
            ckmax(dp[i][l], dp[i - 1][0] - make_pair(p,-1));
            if (l == 1) dp[i][l].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;
    while (r > l) {
        ll mid = l + (r - l) / 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: In function 'pi solve(V<long long int>&, ll, ll)':
feast.cpp:18: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]
   18 |     for (ll i = 1; i <= arr.size(); ++i) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 25544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1024 ms 24564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1027 ms 26312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1093 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1093 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1093 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 25544 KB Time limit exceeded
2 Halted 0 ms 0 KB -