Submission #61678

# Submission time Handle Problem Language Result Execution time Memory
61678 2018-07-26T10:19:35 Z hamzqq9 Homecoming (BOI18_homecoming) C++14
13 / 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+3);

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

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

    }

  } 

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

  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-1]+(i-K+1>=1?A[i-K+1-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-1]+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-1]-(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]);

      }

    }

  }

  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]));

  }
  
  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 8 ms 3556 KB Output is correct
3 Correct 2 ms 3556 KB Output is correct
4 Correct 8 ms 3556 KB Output is correct
5 Correct 3 ms 3556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 8 ms 3556 KB Output is correct
3 Correct 2 ms 3556 KB Output is correct
4 Correct 8 ms 3556 KB Output is correct
5 Correct 3 ms 3556 KB Output is correct
6 Execution timed out 1033 ms 263168 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 290 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 8 ms 3556 KB Output is correct
3 Correct 2 ms 3556 KB Output is correct
4 Correct 8 ms 3556 KB Output is correct
5 Correct 3 ms 3556 KB Output is correct
6 Execution timed out 1033 ms 263168 KB Time limit exceeded
7 Halted 0 ms 0 KB -