Submission #578440

# Submission time Handle Problem Language Result Execution time Memory
578440 2022-06-16T22:55:39 Z jeroenodb Homecoming (BOI18_homecoming) C++14
100 / 100
129 ms 55416 KB
#include "homecoming.h"
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1;
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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 432 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 13652 KB Output is correct
2 Correct 2 ms 832 KB Output is correct
3 Correct 121 ms 55416 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 7 ms 2616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 432 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 29 ms 13652 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 121 ms 55416 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 7 ms 2616 KB Output is correct
16 Correct 129 ms 55412 KB Output is correct
17 Correct 55 ms 20044 KB Output is correct
18 Correct 109 ms 38424 KB Output is correct
19 Correct 77 ms 35368 KB Output is correct
20 Correct 69 ms 38520 KB Output is correct
21 Correct 78 ms 32984 KB Output is correct