제출 #48582

#제출 시각아이디문제언어결과실행 시간메모리
48582faishol27수열 (APIO14_sequence)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pl; #define fi first #define se second const int MAXN = 1e5+5; int N, K; int data[MAXN], pref[MAXN], suff[MAXN]; pl dp[MAXN][205]; //{ind putus, score} int ans = 0, tambah[MAXN][205]; stack<int> putus; pl MAX(pl a, pl b){ if(a.se != b.se){ if(a.se > b.se) return a; else return b; }else{ if(a.fi < b.fi) return a; else return b; } } void cariPemutusan(int pos, ll score){ if(pos == 0) return; for(int i=1;i<=N-1;i++){ if(dp[i][pos].se == score){ putus.push(i); cariPemutusan(pos-1, score-tambah[i][pos]); break; } } } int main(){ memset(data, 0, MAXN); memset(pref, 0, MAXN); memset(suff, 0, MAXN); memset(dp, 0, sizeof dp); memset(tambah, 0, MAXN); cin >> N >> K; for(int i=1;i<=N;i++){ cin >> data[i]; pref[i] = data[i]+pref[i-1]; } for(int i=N;i>0;i--){ suff[i] = suff[i+1]+data[i]; } for(int i=1;i<=N-1;i++){ for(int j=1;j<=K;j++){ for(int l=0;l<i;l++){ pl tmp, bef = dp[l][j-1]; tmp.fi = i; tmp.se = bef.se + (pref[i]-pref[bef.fi])*suff[i+1]; dp[i][j] = MAX(dp[i][j], tmp); if(dp[i][j].se == tmp.se){ tambah[i][j] = (pref[i]-pref[bef.fi])*suff[i+1]; } } } } /* for(int i=1;i<=N-1;i++){ cout << tambah[i] << ": "; for(int j=1;j<=K;j++){ if(j > i) break; cout << "[" << dp[i][j].fi << ", " << dp[i][j].se << "] "; } cout << endl; } */ for(int i=1;i<=N;i++) ans = max(ans, dp[i][K].se); cout << ans << endl; cariPemutusan(K, ans); cout << putus.top(); putus.pop(); while(!putus.empty()){ cout << " " << putus.top(); putus.pop(); } cout << endl; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:84:53: error: no matching function for call to 'max(int&, long long int&)'
     for(int i=1;i<=N;i++) ans = max(ans, dp[i][K].se);
                                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from sequence.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
sequence.cpp:84:53: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
     for(int i=1;i<=N;i++) ans = max(ans, dp[i][K].se);
                                                     ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from sequence.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
sequence.cpp:84:53: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
     for(int i=1;i<=N;i++) ans = max(ans, dp[i][K].se);
                                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
sequence.cpp:84:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
     for(int i=1;i<=N;i++) ans = max(ans, dp[i][K].se);
                                                     ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
sequence.cpp:84:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
     for(int i=1;i<=N;i++) ans = max(ans, dp[i][K].se);
                                                     ^