Submission #173631

# Submission time Handle Problem Language Result Execution time Memory
173631 2020-01-04T18:00:17 Z Nucleist Split the sequence (APIO14_sequence) C++14
0 / 100
2000 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[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);
  if(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

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 Correct 2 ms 376 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 376 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 376 KB contestant found the optimal answer: 0 == 0
4 Correct 2 ms 376 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 2 ms 376 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 2 ms 376 KB contestant found the optimal answer: 1 == 1
7 Correct 2 ms 376 KB contestant found the optimal answer: 1 == 1
8 Correct 2 ms 348 KB contestant found the optimal answer: 1 == 1
9 Correct 2 ms 376 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 2 ms 376 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 2 ms 380 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 2 ms 376 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 3 ms 1016 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 10 ms 1016 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 3 ms 1016 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Incorrect 10 ms 1048 KB Unexpected end of file - int32 expected
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 3752 KB declared answer doesn't correspond to the split scheme: declared = 21503404, real = 14766068
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1624 ms 34040 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 1348 ms 34100 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Execution timed out 2066 ms 34204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -