제출 #541005

#제출 시각아이디문제언어결과실행 시간메모리
541005mansur수열 (APIO14_sequence)C++17
컴파일 에러
0 ms0 KiB
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #include<bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define sz(a) a.size() //#define int long long #define pb push_back #define vt vector #define s second #define f first #define nl '\n' using pii = pair<int, int>; using ll = long long; vt<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int inf = 1e9, N = 1e6 + 5, mod = 1e9 + 7; double eps = 1e-6; bool fl = 0; int ntr(pii a, pii b) { int x = b.f - a.f; int y = a.s - b.s; return (x + y - 1) / y; } void solve() { int n, k; cin >> n >> k; int p[n + 1]; bool is[n + 1][k + 1]; p[0] = 0; for (int i = 1, a; i <= n; i++) { cin >> a; p[i] = p[i - 1] + a; } ll dp[n + 1][k + 1]; for (int i = 0; i <= n; i++) { for (int s = 0; s <= k; s++) dp[i][s] = -inf, is[i][s] = 0; } dp[0][0] = 0; vector<pair<pii, pii>> s; s.pb({{-inf, -1}, {0, 0}}); for (int j = 0; j <= k; j++) { int l = 0; for (int i = j + 1; i <= n; i++) { while (l < sz(s) && s[l].f.s < i && s[l].f.f <= p[i]) l++; dp[i][j] = max(dp[i - 1][j], s[l - 1].s.f + s[l - 1].s.s * p[i]); if (dp[i][j] == dp[i - 1][j]) { is[i][j] = 1; } } s.clear(); for (int i = j + 1; i <= n; i++) { int a = dp[i][j] - p[i] * p[i], b = p[i]; int ps = -inf; if (sz(s) && b == s.back().s.s) { if (a > s.back().s.f) { s.pop_back(); while (sz(s) && ntr({a, b}, s.back().s) <= s.back().f.f) s.pop_back(); if (sz(s)) ps = ntr({a, b}, s.back().s); s.pb({{ps, i}, {a, b}}); } continue; } while (sz(s) && ntr({a, b}, s.back().s) <= s.back().f.f) s.pop_back(); if (sz(s)) ps = ntr({a, b}, s.back().s); s.pb({{ps, i}, {a, b}}); } } cout << dp[n][k] << nl; vector<int> ans; int i = n, j = k; while (j > 0) { if (is[i][j]) { i--; continue; } for (int x = j; x <= i - 1; x++) { int a = dp[x][j - 1] - p[x] * p[x], b = p[x]; if (a + b * p[i] == dp[i][j]) { i = x; j--; ans.pb(x); break; } } } for (auto x: ans) cout << x << ' '; } main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); int tp = 1; if (fl) cin >> tp; while (tp--) solve(); }

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

sequence.cpp: In function 'void solve()':
sequence.cpp:55:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    while (l < sz(s) && s[l].f.s < i && s[l].f.f <= p[i]) l++;
      |             ^
sequence.cpp:56:67: error: no matching function for call to 'max(ll&, int)'
   56 |    dp[i][j] = max(dp[i - 1][j], s[l - 1].s.f + s[l - 1].s.s * p[i]);
      |                                                                   ^
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:4:
/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:56:67: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   56 |    dp[i][j] = max(dp[i - 1][j], s[l - 1].s.f + s[l - 1].s.s * p[i]);
      |                                                                   ^
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:4:
/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:56:67: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   56 |    dp[i][j] = max(dp[i - 1][j], s[l - 1].s.f + s[l - 1].s.s * p[i]);
      |                                                                   ^
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:4:
/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:56:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |    dp[i][j] = max(dp[i - 1][j], s[l - 1].s.f + s[l - 1].s.s * p[i]);
      |                                                                   ^
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:4:
/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:56:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |    dp[i][j] = max(dp[i - 1][j], s[l - 1].s.f + s[l - 1].s.s * p[i]);
      |                                                                   ^
sequence.cpp: At global scope:
sequence.cpp:100:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  100 | main() {
      | ^~~~