Submission #173612

# Submission time Handle Problem Language Result Execution time Memory
173612 2020-01-04T17:27:37 Z Nucleist Split the sequence (APIO14_sequence) C++14
0 / 100
119 ms 131076 KB
#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[100001][201];
ll pref[100001];
set<ll>ans;
ll par[100001][201];
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 = pref[i]-pref[index];
    if(index<0)now=pref[i];
    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);
  //debugs(index+1,k);
  //debug(in);
  if(ans!=lol)par[index+1][k]=in;
  //debugs(index,k);
  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;
  memset(dp,-1,sizeof dp);
  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])
    {
      ans1.insert(i+1);
      recur(par[i][x]+1,par[i][x]+1,x-1);
    }
  }
  for(auto it:ans1)cout<<it<<" ";
  return 0;
}
//code the AC sol !
// BS/queue/map

Compilation message

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 time Memory Grader output
1 Runtime error 119 ms 131072 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 114 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 114 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 117 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -