답안 #530377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530377 2022-02-25T09:04:50 Z Koosha_mv Homecoming (BOI18_homecoming) C++14
100 / 100
205 ms 196248 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=4e6+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(dp[i-1]+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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 39512 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 192 ms 156928 KB Output is correct
4 Correct 2 ms 2128 KB Output is correct
5 Correct 11 ms 4196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 46 ms 39512 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 192 ms 156928 KB Output is correct
14 Correct 2 ms 2128 KB Output is correct
15 Correct 11 ms 4196 KB Output is correct
16 Correct 205 ms 196248 KB Output is correct
17 Correct 83 ms 37740 KB Output is correct
18 Correct 146 ms 46060 KB Output is correct
19 Correct 147 ms 105940 KB Output is correct
20 Correct 162 ms 179552 KB Output is correct
21 Correct 141 ms 103408 KB Output is correct