답안 #61627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61627 2018-07-26T08:25:46 Z hamzqq9 Homecoming (BOI18_homecoming) C++14
0 / 100
239 ms 82788 KB
#ifndef __HOMECOMING_H
#define __HOMECOMING_H
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1000000000000000000
#define umax(x,y) x=max(x,y)

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;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++) {

      umax(dp[1][i+1][j+(j==i-1)],dp[1][i][j]-B[i]+(i+1-K+1>=1?A[i+1-K+1]:0));
      umax(dp[0][i+1][j],dp[1][i][j]);

      if(i+K<=N+1) {

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

      }
      else {

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

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

      }

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

    }

  }

  ll res=0;

  for(int i=0;i<=min(N-1,K);i++) umax(res,max(dp[0][N+1][i],dp[1][N+1][i]));

  return res;

}
#endif
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 239 ms 82788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -