Submission #338626

# Submission time Handle Problem Language Result Execution time Memory
338626 2020-12-23T14:07:42 Z couplefire Homecoming (BOI18_homecoming) C++17
100 / 100
195 ms 133740 KB
#include<bits/stdc++.h>
#include "homecoming.h"
using namespace std;
using lint = long long;
const int MAXN = 4000005;
 
lint a[MAXN], b[MAXN], dp[MAXN];
 
long long solve(int N, int K, int *A, int *B){
	for(int i=1; i<=N; i++){
		a[i] = a[i+N] = A[i-1];
		b[i] = b[i+N] = B[i-1];
	}
	for(int i=1; i<=2*N; i++){
		a[i] += a[i-1];
		b[i] += b[i-1];
	}
	if(K == N){
		return max(0ll, a[N] - b[N]);
	}
	// First DP : Go across the interval
	lint ans = max(0ll, a[N] - b[N]);
	dp[N+1] = 0;
	lint curmax = -1e18;
	for(int i=N; i; i--){
		dp[i] = a[N] - a[i-1] - (b[N] - b[i-1]); // [i, N]
		dp[i] = max(dp[i], dp[i+1]); // Fuck it
		dp[i] = max(dp[i], curmax + b[i-1] - a[i-1]);
		curmax = max(curmax, dp[i] - b[i + K - 2] + a[i - 1]);
		if(i + K - 2 <= N) ans = max(ans, dp[i] + a[i-1] - b[i + K - 2]);
	}
	dp[N+1] = 0;
	curmax = -1e18;
	// Second DP : Act like it never existed
	for(int i=N; i; i--){
		dp[i] = dp[i+1];
		dp[i] = max(dp[i], curmax + b[i-1] - a[i-1]);
		curmax = max(curmax, dp[i] - b[i + K - 2] + a[i - 1]);
	}
	ans = max(ans, dp[1]);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 23788 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 181 ms 94380 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 9 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 51 ms 23788 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 181 ms 94380 KB Output is correct
14 Correct 2 ms 1260 KB Output is correct
15 Correct 9 ms 1388 KB Output is correct
16 Correct 195 ms 133740 KB Output is correct
17 Correct 88 ms 29980 KB Output is correct
18 Correct 161 ms 42840 KB Output is correct
19 Correct 138 ms 74708 KB Output is correct
20 Correct 146 ms 116972 KB Output is correct
21 Correct 165 ms 72152 KB Output is correct