Submission #61675

# Submission time Handle Problem Language Result Execution time Memory
61675 2018-07-26T10:10:57 Z hamzqq9 Homecoming (BOI18_homecoming) C++14
0 / 100
1000 ms 263168 KB
#include "homecoming.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000000000
#define umax(x,y) x=max(x,(y))
#define pw(x) (1<<(x))

ll psum[2000005],psum2[2000005];

long long solve(int N, int K, int *A, int *B) {

  vector< vector<ll> > dp[2];

  for(int i=0;i<2;i++) {

    dp[i].resize(N+2);

    for(int j=0;j<N+2;j++) {

      dp[i][j].resize(K+1);

    }

  } 

  for(int i=N;i>=1;i--) {

    A[i]=A[i-1];
    B[i]=B[i-1];

  }

  for(int i=1;i<=N;i++) {psum[i]=psum[i-1]+B[i];psum2[i]=psum2[i-1]+A[i];}

  for(int i=1;i<=N+1;i++) for(int j=0;j<=min(i-1,K);j++) for(int t=0;t<2;t++) dp[t][i][j]=-inf;

  dp[1][1][0]=0;

  for(int i=1;i<=N;i++) {

    for(int j=0;j<=min(i-1,K);j++) {

      if(dp[1][i][j]!=-inf) {

        if(i<N) umax(dp[1][i+1][min(K,j+(j==i-1))],dp[1][i][j]-B[i]+(i-K+1>=1?A[i-K+1]:0));
        else {
          
          int amount=max(0,min(j+1,K));

          umax(dp[1][N+1][min(K,j+(j==i-1))],dp[1][i][j]-B[i]+psum2[i-K+amount]-psum2[i-K]);

        }

        umax(dp[0][i+1][j],dp[1][i][j]);

      }

      if(dp[0][i][j]!=-inf) {

        if(i+K<=N) {

          umax(dp[1][i+K][j],dp[0][i][j]+A[i]-(psum[i+K-1]-psum[i-1]));

        }
        else {

          int amount=max(0,min(N+1-i,j+N+1-i-K+1));

          umax(dp[1][N+1][j],dp[0][i][j]+psum2[i+amount-1]-psum2[i-1]-(psum[N]-psum[i-1]));

        }

        umax(dp[0][i+1][j],dp[0][i][j]);

      }

    }

  }

  for(int i=1;i<=N;i++) A[i-1]=A[i],B[i-1]=B[i];

  ll res=0;

  for(int i=0;i<=min(N,K);i++) {

    umax(res,max(dp[0][N+1][i],dp[1][N+1][i]));

/*    if(res==47) {

      printf("%d\n%lld %lld\n",i,dp[0][N+1][i],dp[1][N+1][i]);

      return res;

    }*/

  }
  
  umax(res,psum2[N]-psum[N]);

  return res;

}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 9 ms 3548 KB Output is correct
3 Runtime error 8 ms 3548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 9 ms 3548 KB Output is correct
3 Runtime error 8 ms 3548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 239 ms 82996 KB Output is correct
2 Correct 56 ms 82996 KB Output is correct
3 Execution timed out 1052 ms 263168 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 9 ms 3548 KB Output is correct
3 Runtime error 8 ms 3548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -