Submission #73909

# Submission time Handle Problem Language Result Execution time Memory
73909 2018-08-29T09:12:23 Z zscoder Homecoming (BOI18_homecoming) C++17
13 / 100
1000 ms 263168 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "homecoming.h"

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll prefa[4222222];
ll prefb[4222222];

ll suma(int l, int r)
{
	if(l==0) return prefa[r];
	else return prefa[r]-prefa[l-1];
}

ll sumb(int l, int r)
{
	if(l>r) return 0;
	if(l==0) return prefb[r];
	else return prefb[r]-prefb[l-1];
}

const ll INF=ll(1e18);
ll solve(int n, int k, int *a, int *b)
{
	ll ans = 0;
	for(int i=0;i<2*n;i++)
	{
		prefa[i]=a[i%n]; prefb[i]=b[i%n];
		if(i>0) 
		{
			prefa[i]+=prefa[i-1]; prefb[i]+=prefb[i-1];
		}
	}
	ans = max(0LL,prefa[n-1]-prefb[n-1]);
	if(k==n) return ans;
	vector<vector<ll> > dp[2];
	for(int j=0;j<2;j++) 
	{
		dp[j].resize(k+1);
		for(int i=0;i<=k;i++)
		{
			dp[j][i].assign(n,-INF);
		}
	}
	for(int s=0;s<=min(n-1,k);s++)
	{
		//s must be a starting point
		dp[1][s][s] = a[s] - sumb(s,s+k-1);
		ans=max(ans,dp[1][s][s]);
		if(s==k)
		{
			dp[0][s][s]=0;
		}
		for(int i=s+1;i<n;i++)
		{
			dp[0][s][i] = max(dp[0][s][i-1], dp[1][s][i-1]);
			dp[1][s][i] = max(dp[0][s][i-1] + a[i] - sumb(i, min(n+s-1, i+k-1)), dp[1][s][i-1] + a[i] - (i+k-1>=n+s?0:b[(i+k-1)%n]));
			//cerr<<0<<' '<<s<<' '<<i<<' '<<dp[0][s][i]<<'\n';
			//cerr<<1<<' '<<s<<' '<<i<<' '<<dp[1][s][i]<<'\n';
			ans=max(ans,dp[0][s][i]);
			ans=max(ans,dp[1][s][i]);
		}
	}
	return ans;
}	

/*
int aaaa[2111111];
int bbbb[2111111];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>aaaa[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>bbbb[i];
	}
	cout<<solve(n,k,aaaa,bbbb)<<'\n';
}
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 3688 KB Output is correct
3 Correct 3 ms 3688 KB Output is correct
4 Correct 5 ms 3688 KB Output is correct
5 Correct 4 ms 3688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 3688 KB Output is correct
3 Correct 3 ms 3688 KB Output is correct
4 Correct 5 ms 3688 KB Output is correct
5 Correct 4 ms 3688 KB Output is correct
6 Correct 3 ms 3688 KB Output is correct
7 Execution timed out 1042 ms 263168 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 3688 KB Output is correct
3 Correct 3 ms 3688 KB Output is correct
4 Correct 5 ms 3688 KB Output is correct
5 Correct 4 ms 3688 KB Output is correct
6 Correct 3 ms 3688 KB Output is correct
7 Execution timed out 1042 ms 263168 KB Time limit exceeded
8 Halted 0 ms 0 KB -