Submission #855325

#TimeUsernameProblemLanguageResultExecution timeMemory
855325vjudge1Split the sequence (APIO14_sequence)C++17
0 / 100
2 ms348 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") using namespace std; using lol= long long int; typedef long long ll; typedef long double ld; typedef long long unsigned lli; // #define _MAXM 16000 #define cl clear #define int ll #define db double #define pb push_back #define ers erase #define ds resize #define W INT_MIN #define mp make_pair #define pll pair< long , long > #define pii pair<ll, ll> #define bc back() mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count()); #define doc (clock() * 1.0 / CLOCKS_PER_SEC) < 1.0 #define all(v) v.begin(),v.end() const int MAX = 100 + 5; const int LOG = 18; const ll INF = 1e9 + 7; const ll inf = 1e18; const int maxn = 1e5+5; const double me = 1e-9; const double PI=acos(-1.0); const int M= 1e6; const int mod = 998244353; const int mxn=2e5+3; const int MAXA = 1e6 + 10; const int MOD = 1e9 + 7; const int DN = 4008; const int N = 1e5 + 123; int n, k; void kick(){ cin >> n >> k; vector< int > a(n + 1); for(int i = 1; i <= n; i++){ cin >> a[i]; } vector < vector< int > > dp(k + 2, vector< int >(n + 2, -INF)); vector < vector<int> > p(k + 2, vector<int>(n + 2, 0)); dp[0][0] = 0; vector< int> pref(n + 2, 0); for(int i = 1; i <= n; i++){ pref[i] += pref[i - 1]; pref[i] += a[i]; } for(int i = 1; i <= k + 1; i++){ for(int j = 1; j <= n; j++){ for(int k = 0; k < j; k++){ if(dp[i][j] < dp[i - 1][k] + (pref[j] - pref[k]) * pref[k]){ dp[i][j] = dp[i - 1][k] + (pref[j] - pref[k]) * pref[k]; p[i][j] = k; } } } } vector< int > ans; int cur = n; for(int i = k; i > 0; i--){ ans.push_back(p[i + 1][cur]); cur = p[i + 1][cur]; } cout << dp[k + 1][n] << '\n'; reverse( ans.begin(), ans.end()); for(auto &i: ans){ cout << i << " "; } } signed main(){ #ifndef ONLINE_JUDGE freopen("input.in", "r" ,stdin); freopen("output.in", "w", stdout); #endif ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T = 1; // cin >> T; // cout.flush(); while(T--){ kick(); } return 0; }

Compilation message (stderr)

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