제출 #130342

#제출 시각아이디문제언어결과실행 시간메모리
130342qkxwsmHomecoming (BOI18_homecoming)C++14
100 / 100
354 ms196224 KiB
#include <bits/stdc++.h>
#include "homecoming.h"

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define LLINF 2696969696969696969ll
#define MAXN 4000013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, K;
ll A[MAXN], B[MAXN];
ll pref[MAXN];
ll dp[MAXN][2][2];
ll ans;

ll range(int l, int r)
{
	return pref[r + 1] - pref[l];
}
ll solve(int n, int k, int *a, int *b)
{
	N = n; K = k;
	FOR(i, 0, N)
	{
		A[i] = a[i];
		B[i] = b[i];
		B[i + N] = b[i];
	}
	FOR(i, 0, 2 * N)
	{
		pref[i + 1] = pref[i] + B[i];
	}
	FOR(i, 0, N)
	{
		FOR(j, 0, 2)
		{
			FOR(k, 0, 2)
			{
				dp[i][j][k] = -LLINF;
			}
		}
	}
	dp[0][0][0] = 0;
	dp[0][1][1] = A[0] - range(0, K - 1);
	FOR(i, 1, N)
	{
		ckmax(dp[i][1][1], dp[i - 1][1][1] + A[i] - (i + K - 1 >= N ? 0 : B[i + K - 1]));
		ckmax(dp[i][1][1], dp[i - 1][0][1] + A[i] - range(i, min(N - 1, i + K - 1)));
		ckmax(dp[i][1][0], dp[i - 1][1][0] + A[i] - B[i + K - 1]);
		ckmax(dp[i][1][0], dp[i - 1][0][0] + A[i] - range(i, i + K - 1));
		ckmax(dp[i][0][1], dp[i - 1][1][1]);
		ckmax(dp[i][0][1], dp[i - 1][0][1]);
		ckmax(dp[i][0][0], dp[i - 1][1][0]);
		ckmax(dp[i][0][0], dp[i - 1][0][0]);
	}
	ans = 0;
	FOR(i, 0, 2)
	{
		FOR(j, 0, 2)
		{
			ckmax(ans, dp[N - 1][i][j]);
		}
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...