답안 #853203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853203 2023-09-23T15:57:02 Z faruk Homecoming (BOI18_homecoming) C++17
31 / 100
237 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]));
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 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 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 66900 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Runtime error 237 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 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 Correct 1 ms 348 KB Output is correct
11 Correct 73 ms 66900 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Runtime error 237 ms 262144 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -