Submission #853200

# Submission time Handle Problem Language Result Execution time Memory
853200 2023-09-23T15:51:04 Z faruk Homecoming (BOI18_homecoming) C++17
13 / 100
248 ms 262144 KB
#include <bits/stdc++.h>
#include "homecoming.h"
#define mp make_pair
#define all(a) a.begin(), a.end()

using namespace std;

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

const ll INF = 1e18;

struct pref_sum {
    vector<ll> a;
    ll n;
    pref_sum() {}
    pref_sum(int *A, ll s) {
        n = s;
        a.resize(n);
        for (ll i = 0; i < n; i++)
            a[i] = A[i], a[i] += i == 0 ? 0 : a[i - 1];
    }

    ll get(ll l, ll r) {
        if (l <= r) 
            return a[r] - (l == 0 ? 0 : a[l - 1]);
        return a[l] + get(r, n - 1);
    }
};

ll n, k;
pref_sum val;
pref_sum cost;

ll cmp1(pii a, pii b) {return a.first < b.first;}

ll solve(int N, int K, int *A, int *B) {
    n = N, k = K;
    val = pref_sum(A, N);
    cost = pref_sum(B, N);
    vector<vector<ll> > dp(n, vector<ll>(2, -INF));
    // take 1
    dp[0][1] = (ll)A[0] - cost.get(0, k - 1);
    for (ll i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        ll val_continue = dp[i - 1][1] + (ll)A[i];
        if (i + k - 1 < n)
            val_continue -= cost.get(i + k - 1, i + k - 1);
        ll val_begin_new = dp[i - 1][0] + (ll)A[i] - (cost.a[min(i + k - 1, n - 1)] - cost.a[i - 1]);
        dp[i][1] = max(val_continue, val_begin_new);
    }

    ll out = max(dp[n - 1][0], dp[n - 1][1]);

    dp = vector<vector<ll> >(n, vector<ll>(2, -INF));
    dp[0][0] = 0;
    for (ll i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        ll val_continue = dp[i - 1][1] + (ll)A[i];
        val_continue -= cost.get((i + k - 1) % n, (i + k - 1) % n);

        ll val_begin_new = dp[i - 1][0] + (ll)A[i] - (cost.a[min(i + k - 1, n - 1)] - cost.a[i - 1]);
        if (i + k - 1 > n)
            val_begin_new -= cost.a[(i + k - 1) % n];
        dp[i][1] = max(val_continue, val_begin_new);
    }

    return max(out, max(dp[n - 1][0], dp[n - 1][1]));
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Incorrect 1 ms 600 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 66980 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Runtime error 248 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Incorrect 1 ms 600 KB Output isn't correct
11 Halted 0 ms 0 KB -