Submission #173635

#TimeUsernameProblemLanguageResultExecution timeMemory
173635NucleistSplit the sequence (APIO14_sequence)C++14
50 / 100
2048 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; ll nb,x; ve hedi; ll dp[100011][211]; ll pref[100011]; set<ll>ans; ll par[100011][211]; ll solve(ll index,ll k) { if(k==0)return 0; else if(index==nb)return -INF; if(dp[index+1][k]!=-1)return dp[index+1][k]; ll ans=0; ll yup=0,dup=0,in=0; for (ll i = index+1; i < nb; ++i) { ll now=0; if(index<0)now=pref[i]; else now = pref[i]-pref[index]; ll kow = pref[nb-1]-pref[i]; ll dol = kow*now; ll sol = dol+solve(i,k-1); if(ans<sol) { in=i; } ans=max(ans,sol); } ll lol = solve(index+1,k); ans=max(ans,lol); par[index+1][k]=in; return dp[index+1][k]=ans; } set<ll>ans1; void recur(ll node,ll x,ll y) { ans1.insert(node); if(!y)return; recur(par[x][y]+1,par[x][y]+1,y-1); } int main() { flash; cin>>nb>>x; for (int i = 0; i <= nb+1; ++i) { for (int j = 0; j <= x+1; ++j) { dp[i][j]=-1; } } ll cur=0; for (ll i = 0; i < nb; ++i) { ll yo; cin>>yo; hedi.pb(yo); cur+=yo; pref[i]=cur; } ll ans=solve(-1,x); cout<<ans<<'\n'; for (ll i = nb; i >= 0; --i) { if(ans==dp[i][x]) { //debug(par[i][x]); //ans1.insert(i+1); recur(par[i][x]+1,par[i][x]+1,x-1); break; } } for(auto it:ans1)cout<<it<<" "; return 0; } //code the AC sol ! // BS/queue/map

Compilation message (stderr)

sequence.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
sequence.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
sequence.cpp: In function 'long long int solve(long long int, long long int)':
sequence.cpp:36:6: warning: unused variable 'yup' [-Wunused-variable]
   ll yup=0,dup=0,in=0;
      ^~~
sequence.cpp:36:12: warning: unused variable 'dup' [-Wunused-variable]
   ll yup=0,dup=0,in=0;
            ^~~
#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...