제출 #1158101

#제출 시각아이디문제언어결과실행 시간메모리
1158101CrabCNH수열 (APIO14_sequence)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 1e5 + 5;
const long long inf = 1e18 + 7;
const int mod = 1e9 + 7;

int n, k;
int a[maxN],trace[maxN][205];
long long pfs[maxN], dp[maxN][5];

void dnc (int x, int l, int r, int optL, int optR) {
    if (l > r) {
        return;
    }
    int m = (l + r) >> 1;
    long long best = -inf;
    int opt = -1;
    for (int i = optL; i <= min (m, optR); i ++) {
        if (best < dp[i - 1][(x & 1) ^ 1] + (pfs[m] - pfs[i - 1]) *  (pfs[n] - pfs[m])) {
            best = dp[i - 1][(x & 1) ^ 1] + (pfs[m] - pfs[i - 1]) *  (pfs[n] - pfs[m]);
            opt = i;
        }
    }
    dp[m][(x & 1)] = best;
    //cout << m << ' ' << x << ' ' << dp[m][x & 1] << ' ' << opt << '\n';
    trace[m][x] = opt - 1;
    dnc (x, l, m - 1, optL, opt);
    dnc (x, m + 1, r, opt, optR); 
}

void solve () {
    cin >> n >> k;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        pfs[i] = pfs[i - 1] + a[i];
    }
    memset (trace, -1, szf (trace));
    for (int i = 1; i <= k + 1; i ++) {
        dnc (i, 1, n, 1, n);
    }
    cout << max (0, dp[n][(k + 1) & 1]) << '\n';
    int curM = n, curX = k + 1;
    vector <int> all;
    while (trace[curM][curX] != -1) {
        all.push_back (trace[curM][curX]);
        curM = trace[curM][curX];
        curX --;       
    }
    reverse (all.begin (), all.end ());
    for (int i = 1; i < (int) all.size (); i ++) {
        cout << all[i] << ' ';
    }
    return;
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfdgb

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'void solve()':
sequence.cpp:54:17: error: no matching function for call to 'max(int, long long int&)'
   54 |     cout << max (0, dp[n][(k + 1) & 1]) << '\n';
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sequence.cpp:54:17: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   54 |     cout << max (0, dp[n][(k + 1) & 1]) << '\n';
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sequence.cpp:54:17: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   54 |     cout << max (0, dp[n][(k + 1) & 1]) << '\n';
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from sequence.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
sequence.cpp:54:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   54 |     cout << max (0, dp[n][(k + 1) & 1]) << '\n';
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from sequence.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
sequence.cpp:54:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   54 |     cout << max (0, dp[n][(k + 1) & 1]) << '\n';
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:72:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:73:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~