제출 #47510

#제출 시각아이디문제언어결과실행 시간메모리
47510Waschbar수열 (APIO14_sequence)C++17
0 / 100
2053 ms64476 KiB
///©Waschbar #include <bits/stdc++.h> #define tmm first #define uu second.first #define vv second.second using namespace std; const int MAXN = 200; const int LOG = 20; const long long INF = 1e10; const int MOD = 1e9+7; long long n, m; int val[MAXN+1], sum[MAXN+1]; int dp[MAXN+1][MAXN+1][201]; pair<int,int> p[MAXN+1][MAXN+1][201]; vector < int > v; void func(int L, int R, int k) { if(k == 0) return; v.push_back(p[L][R][k].first); func(L,p[L][R][k].first,p[L][R][k].second); func(p[L][R][k].first+1,R,k-p[L][R][k].second-1); } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> val[i]; sum[i] = sum[i-1] + val[i]; } for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) for(int k = 0; k <= m; k++){ dp[i][j][k] = -INF; dp[i][j][0] = 0; } for(int dis = 0; dis < n; dis++) for(int L = 1; L+dis <= n; L++){ int R = L+dis; for(int k = 1; k <= m; k++){ if(k > R-L) break; for(int M = L; M < R; M++) for(int P = 0; P < k; P++){ long long x = dp[L][R][k]; dp[L][R][k] = max(dp[L][R][k], dp[L][M][P]+dp[M+1][R][k-P-1] +(sum[M]-sum[L-1])*(sum[R]-sum[M])); if(x != dp[L][R][k]){ p[L][R][k] = {M,P}; } } ///cout << L <<" "<<R<<" "<<k<<" "<<dp[L][R][k] << endl; } } cout << dp[1][n][m] << endl; func(1,n,m); for(int i = 0; i < v.size(); i++) cout << v[i] << " "; return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:41:27: warning: overflow in implicit constant conversion [-Woverflow]
             dp[i][j][k] = -INF;
                           ^~~~
sequence.cpp:68:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); i++)
                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...