답안 #103552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103552 2019-03-31T12:47:51 Z ekrem Homecoming (BOI18_homecoming) C++11
0 / 100
1000 ms 45056 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 1000000007
#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(int i = 0; i < nn; i++){
		a[++n] = A[i];
		xx += A[i];
	}
	for(int i = 0; i < nn; i++)
		a[++n] = A[i];
	n = 0;
	for(int i = 0; i < nn; i++){
		b[++n] = B[i];
		yy += B[i];
	}
	ans = xx - yy;
	for(int i = 0; i < nn; i++)
		b[++n] = B[i];

	for(int 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

	while(1){
		int mx = 0, bas = 0, son = 0;
		for(int i = 1; i <= n; i++)
			for(int 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;
		int i = bas;
		int j = son;
		// cout << i << " " << j << " "<< mx << endl;
		for(int y = i; y <= j; y++){
			a[ (y - 1)%(n/2) + 1 ] = -inf;
			a[ (y - 1)%(n/2) + 1 + (n/2)] = -inf;
		}
		for(int y = i; y <= j + k - 1; y++){
			b[ (y - 1)%(n/2) + 1 ] = inf;
			b[ (y - 1)%(n/2) + 1 + (n/2)] = inf;
		}
		for(int 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;
}


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




# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 45056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -