답안 #915860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915860 2024-01-24T19:29:49 Z JoseSoto Feast (NOI19_feast) C++14
100 / 100
288 ms 17408 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) ((int) (x).size())
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vp = vector<pii>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vb = vector<bool>;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p){return os << '(' << p.fi << ", " << p.se << ')';}
template<typename C, typename T = typename enable_if<!is_same<C, string>::value, typename C::value_type>::type>
ostream& operator<<(ostream &os, const C &v){string sep; for(const T &x : v) os << sep << x, sep = " "; return os;}
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values){
    cout << "[Debug]\n\t" << vars << " = ";
    string d = "[";
    (..., (cout << d << values, d = "] ["));
    cout << "]\n";
}


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

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

    auto DP = [&](ll lambda) -> array<ll,2> {
        vector< array<ll,2> > dp(n + 1), dp2(n + 1);

        for(int i=1; i<=n; i++){
            dp[i][0] = dp[i-1][0];
            dp2[i][0] = dp2[i-1][0];

            if(a[i] - lambda + dp[i-1][1] > dp[i][0]){
                dp[i][0] = a[i] - lambda + dp[i-1][1];
                dp2[i][0] = 1 + dp2[i-1][1];
            }

            dp[i][1] = dp[i][0];
            dp2[i][1] = dp2[i][0];
            if(a[i] + dp[i-1][1] >= dp[i][1]){
                dp[i][1] = a[i] + dp[i-1][1];
                dp2[i][1] = dp2[i-1][1];
            }
        }

        return {dp[n][0], dp2[n][0]};
    };

    ll ini = 0, fin =  1e18, med;
    array<ll,2> ans;
    while(ini < fin){
        med = (ini + fin)/2;
        ans = DP(med);
        if(ans[1] > k) ini = med + 1;
        else fin = med;
    }

    ans = DP(ini);
    cout << ans[0] + ini*ans[1] << "\n";

    return 0;
}

Compilation message

feast.cpp: In function 'void logger(std::string, Args&& ...)':
feast.cpp:27:42: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17'
   27 |     (..., (cout << d << values, d = "] ["));
      |                                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 14668 KB Output is correct
2 Correct 186 ms 15016 KB Output is correct
3 Correct 176 ms 15136 KB Output is correct
4 Correct 214 ms 15032 KB Output is correct
5 Correct 176 ms 14956 KB Output is correct
6 Correct 166 ms 14720 KB Output is correct
7 Correct 182 ms 14752 KB Output is correct
8 Correct 206 ms 14964 KB Output is correct
9 Correct 236 ms 14748 KB Output is correct
10 Correct 169 ms 14904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 13152 KB Output is correct
2 Correct 175 ms 13376 KB Output is correct
3 Correct 158 ms 13104 KB Output is correct
4 Correct 165 ms 13264 KB Output is correct
5 Correct 199 ms 14688 KB Output is correct
6 Correct 189 ms 13064 KB Output is correct
7 Correct 206 ms 13440 KB Output is correct
8 Correct 216 ms 15052 KB Output is correct
9 Correct 164 ms 14688 KB Output is correct
10 Correct 204 ms 13432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 15152 KB Output is correct
2 Correct 227 ms 17020 KB Output is correct
3 Correct 219 ms 15104 KB Output is correct
4 Correct 210 ms 14960 KB Output is correct
5 Correct 210 ms 15144 KB Output is correct
6 Correct 225 ms 17200 KB Output is correct
7 Correct 200 ms 15240 KB Output is correct
8 Correct 191 ms 15128 KB Output is correct
9 Correct 187 ms 15276 KB Output is correct
10 Correct 228 ms 15228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 348 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 0 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 0 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 348 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 0 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 0 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 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 548 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 14668 KB Output is correct
2 Correct 186 ms 15016 KB Output is correct
3 Correct 176 ms 15136 KB Output is correct
4 Correct 214 ms 15032 KB Output is correct
5 Correct 176 ms 14956 KB Output is correct
6 Correct 166 ms 14720 KB Output is correct
7 Correct 182 ms 14752 KB Output is correct
8 Correct 206 ms 14964 KB Output is correct
9 Correct 236 ms 14748 KB Output is correct
10 Correct 169 ms 14904 KB Output is correct
11 Correct 160 ms 13152 KB Output is correct
12 Correct 175 ms 13376 KB Output is correct
13 Correct 158 ms 13104 KB Output is correct
14 Correct 165 ms 13264 KB Output is correct
15 Correct 199 ms 14688 KB Output is correct
16 Correct 189 ms 13064 KB Output is correct
17 Correct 206 ms 13440 KB Output is correct
18 Correct 216 ms 15052 KB Output is correct
19 Correct 164 ms 14688 KB Output is correct
20 Correct 204 ms 13432 KB Output is correct
21 Correct 216 ms 15152 KB Output is correct
22 Correct 227 ms 17020 KB Output is correct
23 Correct 219 ms 15104 KB Output is correct
24 Correct 210 ms 14960 KB Output is correct
25 Correct 210 ms 15144 KB Output is correct
26 Correct 225 ms 17200 KB Output is correct
27 Correct 200 ms 15240 KB Output is correct
28 Correct 191 ms 15128 KB Output is correct
29 Correct 187 ms 15276 KB Output is correct
30 Correct 228 ms 15228 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 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 1 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 348 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 0 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 0 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 0 ms 348 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 2 ms 604 KB Output is correct
53 Correct 1 ms 548 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 253 ms 14932 KB Output is correct
62 Correct 288 ms 17408 KB Output is correct
63 Correct 223 ms 14912 KB Output is correct
64 Correct 227 ms 15200 KB Output is correct
65 Correct 271 ms 15432 KB Output is correct
66 Correct 221 ms 15152 KB Output is correct
67 Correct 231 ms 15036 KB Output is correct
68 Correct 199 ms 15260 KB Output is correct
69 Correct 184 ms 14968 KB Output is correct
70 Correct 234 ms 14872 KB Output is correct