Submission #1268561

#TimeUsernameProblemLanguageResultExecution timeMemory
1268561monaxiaFeast (NOI19_feast)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include <ext/random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define pb push_back
#define ppb pop_back
#define fr first
#define sc second
#define all(v) v.begin(), v.end()
#define vektor vector

using namespace std;
using namespace __gnu_pbds; 

using ll = long long;
using ull = unsigned long long;
using ld = long double;

constexpr ull Mod = 1e9 + 7;
constexpr ull sqr = 547;
constexpr ld eps = 1e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll l, ll r) {if(l <= r) return uniform_int_distribution <ll> (l, r)(rng); return -1;} 

void solve(){ 
    ll n, k;
    cin >> n >> k;

    vector <ll> a(n + 1);
    vector <vector <ll>> dp(n + 1, vector <ll> (2, -1e16)), cnt(n + 1, vector <ll> (2, 0));

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

    ll l = 0, r = 1e9 * n, ans = 0;

    while(l <= r){
        ll mid = (l + r) >> 1;

        dp[0][1] = mid - 1;

        for(int i = 1; i <= n; i ++){
            if(dp[i - 1][0] > dp[i - 1][1]){
                dp[i][0] = dp[i - 1][0];
                cnt[i][0] = cnt[i - 1][0];
            }

            else{
                dp[i][0] = dp[i - 1][1];
                cnt[i][0] = cnt[i - 1][1];
            }

            if(dp[i - 1][1] + a[i] == dp[i - 1][0] + a[i] - mid){
                dp[i][1] = dp[i - 1][1] + a[i];
                cnt[i][1] = max(cnt[i - 1][1], cnt[i - 1][0] + 1);
            }

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

            else{
                dp[i][1] = dp[i - 1][0] + a[i] - mid;
                cnt[i][1] = cnt[i - 1][0] + 1;
            }

            if(dp[i][1] < a[i] - mid){
                dp[i][1] = a[i] - mid;
                cnt[i][1] = 1;
            }
        }

        if(dp[n][0] < dp[n][1]) swap(cnt[n][0], cnt[n][1]);

        if(cnt[n][0] >= k) l = mid + 1;
        else r = mid - 1, ans = mid;
    }

    dp[0][1] = -1e9;

    for(int i = 1; i <= n; i ++){
        if(dp[i - 1][0] > dp[i - 1][1]){
            dp[i][0] = dp[i - 1][0];
            cnt[i][0] = cnt[i - 1][0];
        }

        else{
            dp[i][0] = dp[i - 1][1];
            cnt[i][0] = cnt[i - 1][1];
        }

        if(dp[i - 1][1] + a[i] == dp[i - 1][0] + a[i] - ans){
            dp[i][1] = dp[i - 1][1] + a[i];
            cnt[i][1] = max(cnt[i - 1][1], cnt[i - 1][0] + 1);
        }

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

        else{
            dp[i][1] = dp[i - 1][0] + a[i] - ans;
            cnt[i][1] = cnt[i - 1][0] + 1;
        }

        if(dp[i][1] < a[i] - ans){
            dp[i][1] = a[i] - ans;
            cnt[i][1] = 1;
        }
    }

    cout << max({0, dp[n][1] + cnt[n][1] * ans, dp[n][0] + cnt[n][0] * ans});
} 

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

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

    int t = 1;

    // cin >> t;

    while(t --){
        solve();
        cout << "\n";
    }
}

Compilation message (stderr)

feast.cpp: In function 'void solve()':
feast.cpp:119:16: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
  119 |     cout << max({0, dp[n][1] + cnt[n][1] * ans, dp[n][0] + cnt[n][0] * ans});
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from feast.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
feast.cpp:119:16: note:   candidate expects 2 arguments, 1 provided
  119 |     cout << max({0, dp[n][1] + cnt[n][1] * ans, dp[n][0] + cnt[n][0] * ans});
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
feast.cpp:119:16: note:   candidate expects 3 arguments, 1 provided
  119 |     cout << max({0, dp[n][1] + cnt[n][1] * ans, dp[n][0] + cnt[n][0] * ans});
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
feast.cpp:119:16: note:   deduced conflicting types for parameter '_Tp' ('int' and 'long long int')
  119 |     cout << max({0, dp[n][1] + cnt[n][1] * ans, dp[n][0] + cnt[n][0] * ans});
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
feast.cpp:119:16: note:   deduced conflicting types for parameter '_Tp' ('int' and 'long long int')
  119 |     cout << max({0, dp[n][1] + cnt[n][1] * ans, dp[n][0] + cnt[n][0] * ans});
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp: At global scope:
feast.cpp:122:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  122 | main(){
      | ^~~~
feast.cpp: In function 'int main()':
feast.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |         freopen("COUNTSEQ.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |         freopen("COUNTSEQ.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~