답안 #853196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853196 2023-09-23T15:46:12 Z faruk Homecoming (BOI18_homecoming) C++17
13 / 100
241 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.get(i, min(i + k - 1, n - 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.get(i, (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]));
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 2 ms 1112 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Incorrect 1 ms 1116 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 66896 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Runtime error 241 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 2 ms 1112 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Incorrect 1 ms 1116 KB Output isn't correct
10 Halted 0 ms 0 KB -