Submission #855390

#TimeUsernameProblemLanguageResultExecution timeMemory
855390vjudge1Split the sequence (APIO14_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// #define int long long
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
const int N = 1e5 + 7, mod = 1e9 + 7;
int a[N];
long long dp[N][207], pref[N];
int pr[N][207];
pair<int, int> t[N];
int l = 1, r = 0;
double pere(pair<int, int> a, pair<int, int> b) {
    return double(a.first - b.first) * 1.0LL / double(b.second - a.second);
}
void add(pair<int, int> x) {
    while(l < r && pere(t[r - 1], t[r]) > pere(t[r - 1], x))r --;
    t[++ r] = x;
}
int get(int x) {
    if(l > r)return -1e18;
    int L = l, R = r - 1;
    int res = -1e18;
    int ans = l;
    while(L <= R) {
        int m = (L + R) >> 1;
        res = max(res, pere(t[m], t[m + 1]));
        if(pere(t[m], t[m + 1]) >= x)L = m + 1, ans = m;
        else R = m - 1;
    }
    return max(res, pere(t[ans], t[ans + 1]));
}
void solve() {
    int n, K;
    cin>>n>>K;
    for(int i = 1; i <= n; i++) {
        cin>>a[i];
        pref[i] = pref[i - 1] + a[i];
    }
    long long maxx = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= min(K, i); j++) {
            for(int k = 1; k < i; k++) {
                long long x = dp[k][j - 1] + (pref[i] - pref[k]) * 1ll * pref[k];
                if(x >= dp[i][j]) {
                    dp[i][j] = x;
                    pr[i][j] = k;
                }
            }
        }
    }
    cout << dp[n][K] << '\n';
    int j = pr[n][K];
    int cnt = K;
    vector<int> ans;
    while(j > 0) {
        ans.push_back(j);
        j = pr[j][--cnt];
    }
    reverse(ans.begin(), ans.end());
    for(auto to : ans)cout << to << ' ';
    cout << '\n';
}
signed main() {
    // freopen ("sequence.in", "r", stdin);
    // freopen ("sequence.out", "w", stdout);
    ios_base::sync_with_stdio(NULL);    
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    // int cases = 0;
    while(t -- ) {
        // cases ++;
        // cout << "Case " << cases << ": ";
        solve();
    }    
}
/*

*/

Compilation message (stderr)

sequence.cpp: In function 'double pere(std::pair<int, int>, std::pair<int, int>)':
sequence.cpp:17:40: error: unable to find numeric literal operator 'operator""LL'
   17 |     return double(a.first - b.first) * 1.0LL / double(b.second - a.second);
      |                                        ^~~~~
sequence.cpp:17:40: note: use '-fext-numeric-literals' to enable more built-in suffixes
sequence.cpp: In function 'int get(int)':
sequence.cpp:24:22: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   24 |     if(l > r)return -1e18;
      |                      ^~~~
sequence.cpp:26:15: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   26 |     int res = -1e18;
      |               ^~~~~
sequence.cpp:30:44: error: no matching function for call to 'max(int&, double)'
   30 |         res = max(res, pere(t[m], t[m + 1]));
      |                                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
   30 |         res = max(res, pere(t[m], t[m + 1]));
      |                                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
   30 |         res = max(res, pere(t[m], t[m + 1]));
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |         res = max(res, pere(t[m], t[m + 1]));
      |                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |         res = max(res, pere(t[m], t[m + 1]));
      |                                            ^
sequence.cpp:34:45: error: no matching function for call to 'max(int&, double)'
   34 |     return max(res, pere(t[ans], t[ans + 1]));
      |                                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sequence.cpp:34:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
   34 |     return max(res, pere(t[ans], t[ans + 1]));
      |                                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sequence.cpp:34:45: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
   34 |     return max(res, pere(t[ans], t[ans + 1]));
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
sequence.cpp:34:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   34 |     return max(res, pere(t[ans], t[ans + 1]));
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
sequence.cpp:34:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   34 |     return max(res, pere(t[ans], t[ans + 1]));
      |                                             ^
sequence.cpp: In function 'void solve()':
sequence.cpp:43:15: warning: unused variable 'maxx' [-Wunused-variable]
   43 |     long long maxx = 0;
      |               ^~~~