Submission #530374

# Submission time Handle Problem Language Result Execution time Memory
530374 2022-02-25T09:00:22 Z Koosha_mv Homecoming (BOI18_homecoming) C++14
0 / 100
63 ms 48956 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const ll N=1e6+99,inf=1e17;

ll n,k,ans,a[N],b[N],c[N],d[N],dp[N],pd[N],ps[N];

void build(ll s){
	if(s==0){
		f(i,1,n+1) a[i]=c[i];
		f(i,1,n+1) b[i]=d[i];
		f(i,n+1,n+n+1) b[i]=0;
		a[1]+=inf;
	}
	else{
		f(i,1,n+1) a[i]=c[i];
		f(i,1,n+1) b[i]=d[i],b[i+n]=d[i];
		a[1]-=inf;
	}
}
ll slv(ll s){
	dp[0]=0;
	pd[0]=-inf;
	f(i,1,2*n+1) ps[i]=ps[i-1]+b[i];
	//dbga(a,1,n+1);
	//dbga(b,1,n+n+1);
	f(i,1,n+1){
		pd[i]=max(a[i]-(ps[i+k-1]-ps[i-1]),pd[i-1]+a[i]-b[i+k-1]);
		dp[i]=max(dp[i-1],pd[i]);
		//cout<<i<<" -> "<<dp[i]<<" "<<pd[i]<<endl;
	}
	if(s==0){
		return dp[n]-inf;
	}
	else{
		return dp[n];
	}
}
long long int solve(int N,int K,int *A,int *B){
	ans=0;
	n=N,k=K;
	f(i,1,n+1) c[i]=A[i-1],d[i]=B[i-1];
	build(0);
	maxm(ans,slv(0));
	build(1);
	maxm(ans,slv(1));
	return ans;
}
/*
main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<int> A,B;
	cin>>n>>k;
	f(i,0,n){
		int x;
		cin>>x;
		A.pb(x);
	}
	f(i,0,n){
		int x;
		cin>>x;
		B.pb(x);
	}
	cout<<solve(n,k,A,B);
}
*/
/*
3 2
40 80 100
140 0 20
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Incorrect 1 ms 320 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Incorrect 1 ms 320 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 48956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Incorrect 1 ms 320 KB Output isn't correct
4 Halted 0 ms 0 KB -