Submission #866527

# Submission time Handle Problem Language Result Execution time Memory
866527 2023-10-26T10:22:51 Z farica Homecoming (BOI18_homecoming) C++14
100 / 100
120 ms 118152 KB
#include "homecoming.h" 
#include <bits/stdc++.h>

using namespace std;

const int MAX_N=2000000;
const int N=2e6+6;
long long dp[N][2];

long long int solve(int N, int K, int *A, int *B) {
    int n=N, k=K;
    int a[n], b[n]; 
    long long pref[n];
    for(int i=0; i<n; ++i) a[i] = A[i];
    for(int i=0; i<n; ++i) {
        b[i] = B[i];
        pref[i] = b[i];
        if(i) pref[i] += pref[i-1];
    }
    long long ans;
    dp[0][0] = -1e18;
    dp[0][1] = a[0] - pref[k-1];
    for(int i=1; i<n; ++i) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
        long long val1 = dp[i-1][1] + a[i];
        if((i+k-1)<n) val1 -= b[i+k-1];
        long long val2 = dp[i-1][0] + a[i] - pref[min(i+k-1, n-1)] + pref[i-1];
        dp[i][1] = max(val1,val2);
    }
    ans = dp[n-1][1];
    ans = max(ans, dp[n-1][0]);
    dp[0][1] = -1e18;
    dp[0][0] = 0;
    for(int i=1; i<n; ++i) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
        long long val1 = dp[i-1][1] + a[i] - b[(i+k-1)%n];
        long long val2 = dp[i-1][0] + a[i];
        if((i+k-1)<n) val2 -= pref[i+k-1] - pref[i-1];
        else val2 -= pref[n-1] - pref[i-1] + pref[(i+k-1)%n];
        dp[i][1] = max(val1, val2);
    }
    ans = max(ans, dp[n-1][0]);
    return max(ans, dp[n-1][1]);
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 20572 KB Output is correct
2 Correct 2 ms 920 KB Output is correct
3 Correct 120 ms 118152 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 6 ms 5316 KB Output is correct
# Verdict Execution time Memory 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 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 29 ms 20572 KB Output is correct
12 Correct 2 ms 920 KB Output is correct
13 Correct 120 ms 118152 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 6 ms 5316 KB Output is correct
16 Correct 120 ms 118008 KB Output is correct
17 Correct 53 ms 28424 KB Output is correct
18 Correct 97 ms 42380 KB Output is correct
19 Correct 96 ms 67688 KB Output is correct
20 Correct 86 ms 101276 KB Output is correct
21 Correct 82 ms 65280 KB Output is correct