Submission #281973

# Submission time Handle Problem Language Result Execution time Memory
281973 2020-08-23T18:04:51 Z Atalasion Homecoming (BOI18_homecoming) C++14
0 / 100
85 ms 57720 KB
#include <bits/stdc++.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")
#include "homecoming.h"
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], sm[NN], ps[NN];
int n, k, A[NN], B[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){
		ll ans = 0;
		ll 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';
	ll ans = 0;
	ll 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

homecoming.cpp:18:17: warning: overflow in conversion from 'long int' to 'int' changes value from '1000000000000000010' to '-1486618614' [-Woverflow]
   18 | const int INF = 1000000000000000010;
      |                 ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Runtime error 8 ms 768 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Runtime error 8 ms 768 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 57720 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Runtime error 8 ms 768 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -