제출 #286507

#제출 시각아이디문제언어결과실행 시간메모리
286507BeanZ수열 (APIO14_sequence)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e5 + 5; ll dp[N][2]; int opt[N][205]; ll a[N]; void DP(ll k, ll l, ll r, ll optl, ll optr){ if (l > r) return; int mid = (l + r) >> 1; dp[mid][1] = -1e18; int best = optl; for (int i = optl; i <= min(mid - 1, optr); i++){ if (dp[mid][1] < (dp[i][0] + a[i] * (a[mid] - a[i]))){ dp[mid][1] = dp[i][0] + a[i] * (a[mid] - a[i]); best = i; opt[mid][k] = i; } } DP(k, l, mid - 1, optl, best); DP(k, mid + 1, r, best, optr); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("VietCT.INP", "r")){ freopen("VietCT.INP", "r", stdin); freopen("VietCT.OUT", "w", stdout); } ll n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i], a[i] = a[i] + a[i - 1]; for (int i = 1; i <= k; i++){ DP(i, 1, n, 1, n); for (int j = 1; j <= n; j++){ dp[j][0] = dp[j][1]; } } cout << dp[n][1] << endl; for (int i = k; i >= 1; i--){ cout << opt[n][i] << " "; n = opt[n][i]; } } /* 7 3 4 1 3 4 0 2 3 */

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

sequence.cpp: In function 'void DP(long long int, long long int, long long int, long long int, long long int)':
sequence.cpp:17:50: error: no matching function for call to 'min(int, long long int&)'
   17 |         for (int i = optl; i <= min(mid - 1, optr); i++){
      |                                                  ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
sequence.cpp:17:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   17 |         for (int i = optl; i <= min(mid - 1, optr); i++){
      |                                                  ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
sequence.cpp:17:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   17 |         for (int i = optl; i <= min(mid - 1, optr); i++){
      |                                                  ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
sequence.cpp:17:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   17 |         for (int i = optl; i <= min(mid - 1, optr); i++){
      |                                                  ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
sequence.cpp:17:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   17 |         for (int i = optl; i <= min(mid - 1, optr); i++){
      |                                                  ^
sequence.cpp: In function 'int main()':
sequence.cpp:31:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   31 |                 freopen("VietCT.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:32:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   32 |                 freopen("VietCT.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~