Submission #73960

# Submission time Handle Problem Language Result Execution time Memory
73960 2018-08-29T10:49:04 Z zscoder Homecoming (BOI18_homecoming) C++17
100 / 100
412 ms 141676 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==0) return prefb[r];
	else return prefb[r]-prefb[l-1];
}
 
const ll INF=ll(1e18);
ll dp[4222222][2];
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];
		}
		dp[i][0]=dp[i][1]=-INF;
	}
	ans = max(0LL,prefa[n-1]-prefb[n-1]);
	for(int s=0;s<1;s++)
	{
		for(int i=s;i<n+s;i++)
		{
			for(int j=0;j<2;j++)
			{
				dp[i][j]=-INF;
			}
		}
		for(int i=s;i<n+s;i++)
		{
			if(i==s)
			{
				dp[i][0] = 0;
			}
			else
			{
				dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
				dp[i][1] = max(dp[i-1][0] + a[i%n] - sumb(i%n, i%n+k-1), dp[i-1][1] + a[i%n] - b[(i+k-1)%n]);
			}
		}
		ans=max(ans,max(dp[n-1][0],dp[n-1][1]));
	}
	ll SS = sumb(0,k-1);
	for(int i=0;i<2*n;i++)
	{
		if(i%n<k) b[i%n]=0;
		prefa[i]=a[i%n]; prefb[i]=(i%n<k?0:b[i%n]);
		if(i>0) 
		{
			prefa[i]+=prefa[i-1]; prefb[i]+=prefb[i-1];
		}
		dp[i][0]=dp[i][1]=-INF;
	}
	for(int s=0;s<1;s++)
	{
		for(int i=s;i<n+s;i++)
		{
			for(int j=0;j<2;j++)
			{
				dp[i][j]=-INF;
			}
		}
		for(int i=s;i<n+s;i++)
		{
			if(i==s)
			{
				dp[i][1] = a[i%n] - SS;
			}
			else
			{
				dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
				dp[i][1] = max(dp[i-1][0] + a[i%n] - sumb(i%n, i%n+k-1), dp[i-1][1] + a[i%n] - b[(i+k-1)%n]);
			}
		}
		ans=max(ans,max(dp[n-1][0],dp[n-1][1]));
	}
	return ans;
}
 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 5 ms 1012 KB Output is correct
7 Correct 3 ms 1012 KB Output is correct
8 Correct 3 ms 1012 KB Output is correct
9 Correct 3 ms 1036 KB Output is correct
10 Correct 4 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 35876 KB Output is correct
2 Correct 7 ms 35876 KB Output is correct
3 Correct 412 ms 141628 KB Output is correct
4 Correct 7 ms 141628 KB Output is correct
5 Correct 17 ms 141628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 3 ms 616 KB Output is correct
4 Correct 3 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 5 ms 1012 KB Output is correct
7 Correct 3 ms 1012 KB Output is correct
8 Correct 3 ms 1012 KB Output is correct
9 Correct 3 ms 1036 KB Output is correct
10 Correct 4 ms 1036 KB Output is correct
11 Correct 106 ms 35876 KB Output is correct
12 Correct 7 ms 35876 KB Output is correct
13 Correct 412 ms 141628 KB Output is correct
14 Correct 7 ms 141628 KB Output is correct
15 Correct 17 ms 141628 KB Output is correct
16 Correct 399 ms 141676 KB Output is correct
17 Correct 141 ms 141676 KB Output is correct
18 Correct 260 ms 141676 KB Output is correct
19 Correct 274 ms 141676 KB Output is correct
20 Correct 302 ms 141676 KB Output is correct
21 Correct 271 ms 141676 KB Output is correct