답안 #861518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861518 2023-10-16T11:58:16 Z maks007 Homecoming (BOI18_homecoming) C++14
0 / 100
36 ms 24148 KB
	#include "bits/stdc++.h"
	#include "homecoming.h"

	using namespace std;

	#define intl long long

	intl solve(int n, int k, int *A, int *B) {
		vector <intl> a, b, pref(n);
		function <intl(intl)> get=[&](intl l) {
			intl r = l + k - 1;
			if(r < n) return pref[r] - (l?pref[l-1]:0);
			r %= n;
			return pref[r] + (pref[n-1] - (l?pref[l-1]:0));
		};
		for(int i = 0; i < n; i ++) a.push_back(A[i]);
		for(int i = 0; i < n; i ++) b.push_back(B[i]);
		for(int i = 0; i < n; i ++) {
			if(i) pref[i] = pref[i-1];
			pref[i] += b[i];
		}
		intl dp[n][2];
		for(auto &i : dp) {
			for(auto &j : i) j = -LLONG_MAX;
		}
		dp[0][1] = a[0] - pref[k-1];
		for(int i = 1; i < n; i ++) {
			dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
			dp[i][1] = max(dp[i-1][1] + a[i] - (i + k - 1 < n ? a[i+k-1] : 0), dp[i-1][0] + a[i] - (pref[min(n-1,i+k-1)] - (i ? pref[i-1] : 0)));
		}
		intl ans = max(dp[n-1][1], dp[n-1][0]);
		dp[0][0] = 0;
		for(int i = 1; i < n; i ++) {
			dp[i][0] = max(dp[i-1][1], dp[i-1][0]);
			dp[i][1] = max(dp[i-1][1] + a[i] - b[(i + k - 1) % n], dp[i-1][0] + a[i] - get(i));
		}
		ans = max({ans, dp[n-1][0], dp[n-1][1]});
		return ans;
	} 
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 24148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -