답안 #578443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578443 2022-06-16T23:17:40 Z jeroenodb Homecoming (BOI18_homecoming) C++14
100 / 100
122 ms 15948 KB
#include "homecoming.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

const ll oo = -1e18;
long long solve(int N, int K, int *A, int *B) {
    int n = N,k = K;
    ll ans = 0;
    for(int rep=0;rep<2;++rep) {
        // rep==0: include a[0] certainly, so extra cost beyond the boundary does not have to be counted.
        // rep==1: doesn't matter if a[0] gets chosen or not.
        ll dp[2] = {};
        if(rep==0) dp[0] = oo;
        ll cost=0;
        for(int i=0;i<k;++i) cost+=B[i];
        dp[1] = A[0]-cost;
        
        for(int i=1;i<n;++i) {
            cost-=B[i-1];
            int extra=0;
            if(i+k-1<n) {
                extra = B[i+k-1];
            } else if(rep==1) {
                extra = B[i+k-1-n];
            }
            cost+=extra;
            tie(dp[0],dp[1]) = make_pair(max(dp[0],dp[1]), A[i]+ max(dp[0]-cost,dp[1]-extra));
        }
        ans = max({ans,dp[0],dp[1]});
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 4172 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 122 ms 15908 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 5 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 29 ms 4172 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 122 ms 15908 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 5 ms 404 KB Output is correct
16 Correct 102 ms 15948 KB Output is correct
17 Correct 53 ms 2348 KB Output is correct
18 Correct 96 ms 1436 KB Output is correct
19 Correct 96 ms 8168 KB Output is correct
20 Correct 70 ms 15948 KB Output is correct
21 Correct 64 ms 8276 KB Output is correct