답안 #281971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281971 2020-08-23T18:00:04 Z Atalasion Homecoming (BOI18_homecoming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "homecoming.h"
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int NN = 2000000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000000000000010;
const int delta = 11353;

ll dp[NN][2], A[NN], B[NN], n, k, sm[NN], ps[NN];

ll solve(int N, int K, int *A, int *B){
	ps[0] = 0;
	n = N;
	for (int i = n; i < 2 * n; i++) B[i] = B[i - n];
	for (int i = 1; i <= 2 * n; i++){
		ps[i] = ps[i - 1] + B[i - 1];
	//	cout << i << ' ' << ps[i] << '\n';
	}
	if (K == n){
		int ans = 0;
		int Sum = 0;
		for (int i = 0; i < n; i++) Sum += A[i], Sum -= B[i];
		return max(ans, Sum);
	}
	for (int i = 0; i < n; i++)sm[i] = ps[i + 1 + K - 1] - ps[i];
//	for (int i = 0; i < n; i++) cout << i << ' ' << sm[i] << '\n';
	int ans = 0;
	int Sum = 0;
	for (int i = 0; i < n; i++) Sum += A[i], Sum -= B[i];
	ans = max(ans, Sum);
	for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) dp[i][j] = -INF;
	dp[n - 1][0] = 0, dp[n - 1][1] = A[n - 1] - B[n - 1];
	//cout << dp[n - 1][0] << ' ' << dp[n - 1][1] << '\n';
	for (int i = n - 2; i >= 0; i--){
		dp[i][0] = max(dp[i + 1][1], dp[i + 1][0]);
		dp[i][1] = max(dp[i + 1][0] + A[i] - sm[i], dp[i + 1][1] + A[i] - B[i]);
		//cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << '\n';
	}
	Sum = A[0] - sm[0];
	for (int i = 1; i < n; i++){
		ans = max(ans, dp[i][0] + Sum);
		Sum += sm[i - 1] - B[i - 1];
		Sum += A[i] - sm[i];
	}
	//cout << ans << '\n';
	for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) dp[i][j] = -INF;
	dp[n - 1][0] = 0, dp[n - 1][1] = A[n - 1] - sm[n - 1];
	for (int i = n - 2; i >= 0; i--){
		dp[i][0] = max(dp[i + 1][0], dp[i + 1][1]);
		dp[i][1] = max(dp[i + 1][0] + A[i] - sm[i], dp[i + 1][1] + A[i] - B[i]);
		//cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << '\n';
	}
	ans = max(ans, dp[0][0]);
	return ans;
}

Compilation message

/tmp/cci9jDPO.o: In function `main':
grader.cpp:(.text.startup+0xee): undefined reference to `solve(int, int, int*, int*)'
collect2: error: ld returned 1 exit status