Submission #103554

# Submission time Handle Problem Language Result Execution time Memory
103554 2019-03-31T12:50:55 Z ekrem Homecoming (BOI18_homecoming) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 1000000000000007
#define N 1000005
using namespace std;

typedef long long ll;

ll n, k, xx, yy, top, ans, a[N], b[N], x[N], pre[N];

ll solve(int nn, int K, int *A, int *B){
	k = K;
	for(ll i = 0; i < nn; i++){
		a[++n] = A[i];
		xx += A[i];
	}
	for(ll i = 0; i < nn; i++)
		a[++n] = A[i];
	n = 0;
	for(ll i = 0; i < nn; i++){
		b[++n] = B[i];
		yy += B[i];
	}
	ans = xx - yy;
	for(ll i = 0; i < nn; i++)
		b[++n] = B[i];

	for(ll i = 1; i <= n; i++){
		// cout << a[i] << " " << b[i] << endl;
		x[i] = x[i - 1] + a[i];
		pre[i] = pre[i - 1] + b[i];
	}
//tanim
	if(n != 1)
	while(1){
		ll mx = 0, bas = 0, son = 0;
		for(ll i = 1; i <= n; i++)
			for(ll j = i; j <= n; j++){
				if(j + k - 1 <= n and j + k - 1 - i + 1 < n/2){
					if(x[j] - x[i - 1]  - (pre[j + k - 1] - pre[i - 1]) > mx){
						mx = x[j] - x[i - 1]  - (pre[j + k - 1] - pre[i - 1]);
						bas = i;
						son = j;
					}
				}
			}
		if(!mx)
			break;
		ll i = bas;
		ll j = son;
		// cout << i << " " << j << " "<< mx << endl;
		for(ll y = i; y <= j; y++){
			a[ (y - 1)%(n/2) + 1 ] = -inf;
			a[ (y - 1)%(n/2) + 1 + (n/2)] = -inf;
		}
		for(ll y = i; y <= j + k - 1; y++){
			b[ (y - 1)%(n/2) + 1 ] = inf;
			b[ (y - 1)%(n/2) + 1 + (n/2)] = inf;
		}
		for(ll i = 1; i <= n; i++){
			x[i] = x[i - 1] + a[i];
			pre[i] = pre[i - 1] + b[i];
		}
		top += mx;
		// if(rand()%10 == 0)
			// break;
	}
	ans = max(ans, top);
	return ans;
}


ll _A[N], _B[N];
int main() {
	freopen("in.txt", "r", stdin);
	freopen("outt.txt", "w", stdout);
	ll nn, K;
	scanf("%lld %lld",&nn ,&K);
	for(ll i = 0; i < nn; i++)
		scanf("%lld",_A + i);
	for(ll i = 0; i < nn; i++)
		scanf("%lld",_B + i);
	cout << solve(nn, K, _A, _B);
	return 0;
}




Compilation message

homecoming.cpp: In function 'int main()':
homecoming.cpp:86:29: error: cannot convert 'll* {aka long long int*}' to 'int*' for argument '3' to 'll solve(int, int, int*, int*)'
  cout << solve(nn, K, _A, _B);
                             ^
homecoming.cpp:78:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("in.txt", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
homecoming.cpp:79:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("outt.txt", "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
homecoming.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&nn ,&K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
homecoming.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",_A + i);
   ~~~~~^~~~~~~~~~~~~~~
homecoming.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",_B + i);
   ~~~~~^~~~~~~~~~~~~~~