이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "homecoming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = (int)2e6 + 7;
const ll linf = (ll)1e18 + 7;
ll pref[N + N];
ll dp[N][2][2];
ll get(int l, int r) {
if (!l) return pref[r];
return pref[r] - pref[l - 1];
}
ll solve(int n, int k, int a[], int b[]) {
pref[0] = b[0];
for (int i = 0; i < n + n; i++) {
pref[i + 1] = pref[i] + b[(i + 1) % n];
}
for (int i = 0; i < N; i++)
for (int j = 0; j < 2; j++)
for (int l = 0; l < 2; l++)
dp[i][j][l] = -linf;
dp[0][1][1] = a[0] - pref[k - 1];
dp[0][0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 2; j++) {
dp[i][0][j] = max(dp[i - 1][0][j], dp[i - 1][1][j]);
if (j == 0 || i + k - 1 < n) {
dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, i + k - 1), dp[i - 1][1][j] + a[i] - b[(i + k - 1) % n]);
} else {
dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, n - 1), dp[i - 1][1][j] + a[i]);
}
// cout << i << ' ' << j << ' ' << dp[i][0][j] << ' ' << dp[i][1][j] << endl;
}
}
ll ans = 0;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
ans = max(ans, dp[n - 1][i][j]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |