답안 #674752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674752 2022-12-26T07:07:31 Z QwertyPi Feast (NOI19_feast) C++14
8 / 100
206 ms 27180 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 3e5 + 11;
int a[MAXN], dp[MAXN], dp2[MAXN], c[MAXN], c2[MAXN];

int32_t main(){
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	auto test = [&n](int C) {
		fill(dp, dp + MAXN, -(1LL << 60));
		fill(dp2, dp2 + MAXN, -(1LL << 60));
		fill(c, c + MAXN, 0);
		fill(c2, c2 + MAXN, 0);
		dp[0] = -(1LL << 60), dp2[0] = 0;
		for(int j = 0; j < n; j++){
			if(dp2[j - 1] + a[j] - C >= dp[j] + a[j]){
				dp[j + 1] = dp2[j - 1] + a[j] - C;
				c[j + 1] = c2[j - 1] + 1;
			}else{
				dp[j + 1] = dp[j] + a[j]; 
				c[j + 1] = c[j];
			}
			if(dp2[j] >= dp[j + 1]){
				dp2[j + 1] = dp2[j];
				c2[j + 1] = c2[j];
			}else{
				dp2[j + 1] = dp[j + 1];
				c2[j + 1] = c[j + 1];
			}
		}
	};
	
	int l = 0, r = 1 << 30;
	while(l + 1 != r){
		int mid = (l + r) / 2;
		test(mid);
		if(c2[n] > k){
			l = mid;
		}else{
			r = mid;
		}
	}
	test(l); int v1 = dp2[n] + l * c2[n], k1 = c2[n];
	test(r); int v2 = dp2[n] + r * c2[n], k2 = c2[n];
	cout << v1 + (v2 - v1) / (k2 - k1) * (k - k1) << endl; 
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 171 ms 26788 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 13080 KB Output is correct
2 Correct 114 ms 13152 KB Output is correct
3 Correct 108 ms 13068 KB Output is correct
4 Correct 115 ms 13096 KB Output is correct
5 Correct 182 ms 14752 KB Output is correct
6 Correct 106 ms 13004 KB Output is correct
7 Correct 116 ms 13136 KB Output is correct
8 Correct 154 ms 14820 KB Output is correct
9 Correct 154 ms 14668 KB Output is correct
10 Correct 104 ms 13068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 206 ms 27180 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 19408 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 19408 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 19408 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 171 ms 26788 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -