답안 #68923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68923 2018-08-19T09:14:21 Z istlemin Homecoming (BOI18_homecoming) C++14
0 / 100
127 ms 33392 KB
#include<bits/stdc++.h>
#include "homecoming.h"

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

ll n,k;
vi a,b;
vi sumB;
ll start;

ll getSum(ll l,ll r){
	if(r<l) return 0;
    return sumB[r]-sumB[l];
}

ll getCost(ll l,ll r){
	if(l>=n) return getCost(l-n,r-n);
    if(r>n) return getCost(l,n)+getCost(0,r-n);
    if(l<start) return getSum(start,r);
    return getSum(l,r);
}

long long solve(int N, int K, int *A, int *B){
	n = N; k = K;
	a.resize(n);
	b.resize(n);
	rep(i,0,n) a[i] = A[i];
	rep(i,0,n) b[i] = B[i];
    sumB.resize(n+1);
    rep(i,1,n+1) sumB[i] = sumB[i-1]+b[i-1];

    ll best = 0;

    rep(_start,0,k-1){
        start = _start;
        ll curr = -getSum(0,start);

        vi dpFilled(n+k+1);
        vi dpEmpty(n+k+1);

        for(int i = n-1;i>=0;i--){
            ll cost = getCost(i+k-1,i+k);
            dpFilled[i] = max(dpFilled[i],a[i]-cost+dpFilled[i+1]);
            dpFilled[i] = max(dpFilled[i],dpEmpty[i+k]);

            cost = getCost(i,i+k);
            dpEmpty[i] = max(dpEmpty[i],a[i]-cost+dpFilled[i+1]);
            dpEmpty[i] = max(dpEmpty[i],dpEmpty[i+1]);
        }

        curr += dpEmpty[0];

        best = max(best,curr);
    }

    return best;
}
# 결과 실행 시간 메모리 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 Correct 127 ms 33392 KB Output is correct
2 Incorrect 35 ms 33392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -