Submission #106388

#TimeUsernameProblemLanguageResultExecution timeMemory
106388abilSplit the sequence (APIO14_sequence)C++14
50 / 100
2050 ms32032 KiB
#include <bits/stdc++.h> #define int long long #define mk make_pair #define sc second #define fr first #define pb emplace_back #define all(s) s.begin(), s.end() #define sz(s) ( (int)s.size() ) #define Scan(a) scanf ("%I64d", &a) #define scan(a) scanf ("%d", &a) #define pi pair < long long, long long > using namespace std; const long long INF = (int)1e18 + 7; const int N = (int)10007; const int mod = 1000000007; int n, k, arr[N], pr[N], par[10007][201]; int dp[N][201]; main(){ cin >> n >> k; for(int i = 1;i <= n; i++){ cin >> arr[i]; pr[i] = pr[i - 1] + arr[i]; } for(int g = 1;g <= k; g++){ for(int i = 1;i <= n; i++){ for(int j = 1;j < i; j++){ if(dp[i][g] <= dp[j][g - 1] + (pr[j] * (pr[i] - pr[j]))){ par[i][g] = j; dp[i][g] = dp[j][g - 1] + (pr[j] * (pr[i] - pr[j])); } } } } cout << dp[n][k] << endl; vector<int > ans; while(par[n][k]){ ans.pb(par[n][k]); n = par[n][k]; k--; } for(int i = ans.size() - 1; i >= 0; i--){ cout << ans[i] << " "; } } /* 7 3 4 1 3 4 0 2 3 */

Compilation message (stderr)

sequence.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#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...