답안 #578444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578444 2022-06-16T23:18:46 Z jeroenodb Homecoming (BOI18_homecoming) C++14
100 / 100
120 ms 16076 KB
#include "homecoming.h"
#include <algorithm>
#include <tuple>
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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 340 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 23 ms 4180 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 94 ms 16076 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 5 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 23 ms 4180 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 94 ms 16076 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 5 ms 480 KB Output is correct
16 Correct 120 ms 15968 KB Output is correct
17 Correct 45 ms 2236 KB Output is correct
18 Correct 85 ms 1436 KB Output is correct
19 Correct 61 ms 8112 KB Output is correct
20 Correct 59 ms 15912 KB Output is correct
21 Correct 63 ms 8216 KB Output is correct