Submission #498153

#TimeUsernameProblemLanguageResultExecution timeMemory
498153EliteCallsYouSplit the sequence (APIO14_sequence)C++17
11 / 100
2083 ms2508 KiB
# include <bits/stdc++.h> using namespace std ; //############################################################################ # define read(a)/**/for(int i=0;i<int(sizeof(a)/sizeof(a[0]));i++){cin>>a[i];} # define print(x)/**/for(auto zx:x){cout<<zx<<' ';} const char* tochar(string a){return a.c_str();} void files(){freopen("hopscotch.in","r",stdin);freopen("hopscotch.out","w",stdout);} void speed(){ios_base::sync_with_stdio(false);cin.tie(0);} long long gcd(long long a,long long b){if(!b){return a;}a%=b;return gcd(b,a);} long long lcm(long long a,long long b){return a /gcd(a,b) * b;} //########################################################################### const int N = 1e5 + 5 ; const long long MOD = 1e9+7 ; //########################################################################### void hack(){} //########################################################################### long long n, m, ar[N], pref[N], suff[N], mx, ans ; vector < long long > cur, vc ; void rec ( int cuts, int pos ){ if ( cuts == m ){ if ( ans >= mx ){ vc = cur ; mx = ans ; } return ; } if ( pos == n ){return;} for ( int i = pos ; i < n ; i ++ ){ cur.push_back(i) ; ans += (pref[i]-pref[pos-1])*suff[i+1] ; ///////////////// rec(cuts+1,i+1) ; ///////////////// cur.pop_back() ; ans -= (pref[i]-pref[pos-1])*suff[i+1] ; } } int main(){ cin >> n >> m ; for ( int i = 1 ; i <= n ; i ++ ){ cin >> ar[i] ; pref[i] = pref[i-1]+ar[i] ; } for ( int i = n ; i >= 1 ; i -- ){ suff[i] = suff[i+1]+ar[i] ; } if ( !m ){ cout << 0 << '\n' ; return 0 ; } /////////////////////////////////// for ( int i = 1 ; i < n ; i ++ ){ cur.push_back(i) ; ans += pref[i] * suff[i+1] ; //////////////// rec(1,i+1) ; //////////////// cur.pop_back() ; ans -= pref[i] * suff[i+1] ; } cout << mx << '\n' ; for ( int i : vc ){cout<<i<<' ';} }

Compilation message (stderr)

sequence.cpp: In function 'void files()':
sequence.cpp:7:21: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | void files(){freopen("hopscotch.in","r",stdin);freopen("hopscotch.out","w",stdout);}
      |              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:7:55: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | void files(){freopen("hopscotch.in","r",stdin);freopen("hopscotch.out","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...