Submission #73923

# Submission time Handle Problem Language Result Execution time Memory
73923 2018-08-29T09:30:58 Z duckmoon99 Homecoming (BOI18_homecoming) C++14
0 / 100
64 ms 24592 KB
#include "homecoming.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18
#define ret return

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll solve(int n, int k, int *A, int *B){
	ll tA = 0;
	ll tB = 0;
	for(int i = 0; i < n; i++){
		tA+=A[i];
		tB+=B[i];
	}
	ll anss = max(ll(0),tA-tB);
	if(k==1){
		ll ans = 0;
		for(int i = 0; i < n; i++){
			ans+=max(0,A[i]-B[i]);
		}
		ret ans;
	}
	int N = n;
	for(int T = 0; T < N; T++){
		//cout << "**" << t << endl;
		//banning the t-th book
		vi a, b;
		for(int i = 1; i < N; i++){
			a.pb(A[(i+T)%N]);
			b.pb(B[(i+T)%N]);
		}
		n=a.size();
		ll dp[n][k+5];
		ll cost[n];
		cost[0]=b[0];
		for(int i = 1; i < n; i++){
			cost[i]=b[i]+cost[i-1];
		}
		for(int i = n-1; i >= n-k; i--){
			for(int j = k; j >= 0; j--){
				if(i+j-1>=n){
					dp[i][j]=-INF;
				}
				else{
					if(i>0 && j>0){
						ll t = cost[i+j-1];
						t-=cost[i-1];
						dp[i][j]=max(dp[i][j+1],-t+dp[i+j][0]);
					}
					else if(j==0){
						dp[i][j]=max(dp[i][j+1],ll(0));
					}
					else{
						ll t = cost[i+j-1];
						dp[i][j]=max(dp[i][j+1],-t+dp[i+j][0]);
					}
					
				}
				//cout << i << " " << j << " " << dp[i][j] << endl;
			}
		}
		for(int i = n-k-1; i >= 0; i--){
			for(int j = k; j >= 0; j--){
				if(j==k){
					//cout << ",";
					dp[i][j]=a[i]-b[i]+dp[i+1][j-1];
				}
				else{
					if(i>0 && j>0){
						ll t = cost[i+j-1];
						t-=cost[i-1];
						dp[i][j]=max(dp[i][j+1],-t+dp[i+j][0]);
					}
					else if(j==0){
						dp[i][j]=max(dp[i][j+1],ll(0));
					}
					else{
						ll t = cost[i+j-1];
						dp[i][j]=max(dp[i][j+1],-t+dp[i+j][0]);
					}
				}
				//cout << i << " " << j << " " << dp[i][j] << endl;
			}
			assert(dp[i][0]<0);
		}
		anss=max(dp[0][0],anss);
	}
	ret anss;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 24592 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -