Submission #1076323

#TimeUsernameProblemLanguageResultExecution timeMemory
1076323speedcodeSplit the sequence (APIO14_sequence)C++17
0 / 100
10 ms1112 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll MOD = 1000000007; ll dp1[100001][201]; int dp2[100001][201]; int n; int Dat[100001]; ll f(int m, int k){ if(k+1 > n + 1 - m) return 0; if(k == 0) return 0; if(dp1[m][k] != -1) return dp1[m][k]; ll res = 0; for(int i = m+1; i <= n; i++){ ll r = (Dat[i-1] - Dat[m-1])*(Dat[n] - Dat[i-1]) + f(i, k-1); if(r > res){ res = r; dp2[m][k] = i; } } dp1[m][k] = res; return res; } void solve(){ int k; cin >> n >> k; for(int i = 1; i <= n; i++){ for(int j = 0; j <= k; j++){ dp1[i][j] = -1; dp2[i][j] = -1; } } Dat[0] = 0; for(int i = 1; i <= n; i++){ cin >> Dat[i]; Dat[i] += Dat[i-1]; } cout << f(1, k) << '\n'; int key = 1; while(true){ key = dp2[key][k]; if(key == -1) break; cout << key-1 << ' '; k--; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif solve(); }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     freopen("output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...