Submission #568995

#TimeUsernameProblemLanguageResultExecution timeMemory
568995Ronin13수열 (APIO14_sequence)C++14
28 / 100
2089 ms61184 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define ull unsigned ll #define pb push_back #define epb emplace_back #define pii pair<int,int> #define pll pair<ll,ll> using namespace std; ll dp[100001][201]; ll p[100001][201]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int k; cin >> k; ll pref[n + 1]; ll a[n + 1]; for(int i = 1; i <= n; i++){ cin >> a[i]; } pref[0] = 0; for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i]; for(int i = 1; i <= n; i++){ for(int j = 0; j < k; j++){ for(int l = 0; l < i; l++){ ll val = dp[l][j] + (pref[i] - pref[l]) * (pref[n] - pref[i]); if(dp[i][j + 1] < val){ dp[i][j + 1] = val; p[i][j + 1] = l; } } } } ll ans = 0; ll mxi; for(int i = 1; i <= n; i++){ if(ans < dp[i][k]) ans = dp[i][k], mxi = i; } cout << ans << "\n"; int cnt = k; vector <int> vec; while(cnt){ vec.pb(mxi); mxi = p[mxi][cnt]; cnt--; } reverse(vec.begin(), vec.end()); for(auto to : vec) cout << to << ' '; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:47:15: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |         vec.pb(mxi);
      |         ~~~~~~^~~~~
#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...