Submission #422741

# Submission time Handle Problem Language Result Execution time Memory
422741 2021-06-10T11:30:11 Z egekabas Homecoming (BOI18_homecoming) C++14
100 / 100
266 ms 55484 KB
#include <bits/stdc++.h>
#include "homecoming.h"
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
long long solve(int N, int K, int *A, int *B){
    

    ll ans = 0;

    ll cost = 0;
    for(ll i = 0; i < K; ++i)
        cost += B[i];
    vector<ll> dp = {(ll)-1e18, A[0]-cost};
    for(int i = 1; i < N; ++i){
        vector<ll> nw(2, -1e18);
        cost -= B[i-1];
        if(i+K-1 < N)
            cost += B[i+K-1];

        nw[0] = max(dp[0], dp[1]);
        nw[1] = dp[0]+A[i]-cost;
        if(i+K-1 < N)
            nw[1] = max(nw[1], dp[1]+A[i]-B[i+K-1]);
        else
            nw[1] = max(nw[1], dp[1]+A[i]);
        nw[1] = max((ll)-1e18, nw[1]);

        dp = nw;
    }
    ans = max({ans, dp[0], dp[1]});

    cost = 0;
    for(ll i = 0; i < K; ++i)
        cost += B[i];
    dp = {0, (ll)-1e18};
    for(int i = 1; i < N; ++i){
        vector<ll> nw(2, -1e18);
        cost -= B[i-1];
        cost += B[(i+K-1)%N];
        
        nw[0] = max(dp[0], dp[1]);
        
        nw[1] = dp[0]+A[i]-cost;
        nw[1] = max(nw[1], dp[1]+A[i]-B[(i+K-1)%N]);
        
        nw[1] = max((ll)-1e18, nw[1]);
    
        dp = nw;
    }
    ans = max({ans, dp[0], dp[1]});
    return ans;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 4172 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 263 ms 55484 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 18 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 63 ms 4172 KB Output is correct
12 Correct 4 ms 332 KB Output is correct
13 Correct 263 ms 55484 KB Output is correct
14 Correct 3 ms 716 KB Output is correct
15 Correct 18 ms 2496 KB Output is correct
16 Correct 263 ms 55364 KB Output is correct
17 Correct 133 ms 20092 KB Output is correct
18 Correct 266 ms 38528 KB Output is correct
19 Correct 222 ms 35360 KB Output is correct
20 Correct 216 ms 38528 KB Output is correct
21 Correct 227 ms 32856 KB Output is correct